Problem
yew-router strips trailing slashes from both route patterns and incoming pathnames before matching. This means /settings and /settings/ always resolve to the same route variant and render the same component.
However, the browser resolves relative paths differently depending on whether the URL has a trailing slash:
| URL in address bar |
Relative ref ./banner.jpg resolves to |
/settings |
/banner.jpg |
/settings/ |
/settings/banner.jpg |
Because yew-router renders the same component for both, a component that uses relative asset paths will behave correctly for one URL but break for the other.
Steps To Reproduce
- Define a route with a trailing slash:
#[derive(Clone, Routable, PartialEq)]
enum MainRoute {
#[at("/news")]
News,
#[at("/settings/")]
Settings,
}
- In the
Settings component, reference a relative asset like ./banner.jpg, expecting it to resolve to /settings/banner.jpg
- Navigate to
/settings (no trailing slash)
- The component renders, but
./banner.jpg resolves to /banner.jpg instead of /settings/banner.jpg
Note: defining both #[at("/settings")] and #[at("/settings/")] in the same enum panics at router construction due to duplicate insertion (both are stripped to /settings).
Expected behavior
One of:
- Stop stripping trailing slashes.
/settings and /settings/ become distinct routes. Most correct from a URL semantics standpoint but is a breaking change.
- Canonical redirect. When a route is defined as
/settings/ and the user navigates to /settings, automatically redirect to /settings/ so relative-path resolution is consistent.
- Keep current behavior, document the caveat. Recommend absolute paths in routed components.
Environment:
Questionnaire
Context
Problem
yew-routerstrips trailing slashes from both route patterns and incoming pathnames before matching. This means/settingsand/settings/always resolve to the same route variant and render the same component.However, the browser resolves relative paths differently depending on whether the URL has a trailing slash:
./banner.jpgresolves to/settings/banner.jpg/settings//settings/banner.jpgBecause
yew-routerrenders the same component for both, a component that uses relative asset paths will behave correctly for one URL but break for the other.Steps To Reproduce
Settingscomponent, reference a relative asset like./banner.jpg, expecting it to resolve to/settings/banner.jpg/settings(no trailing slash)./banner.jpgresolves to/banner.jpginstead of/settings/banner.jpgNote: defining both
#[at("/settings")]and#[at("/settings/")]in the same enum panics at router construction due to duplicate insertion (both are stripped to/settings).Expected behavior
One of:
/settingsand/settings/become distinct routes. Most correct from a URL semantics standpoint but is a breaking change./settings/and the user navigates to/settings, automatically redirect to/settings/so relative-path resolution is consistent.Environment:
master(also applies after Switch from route-recognizer to matchit #4096)Questionnaire
Context