-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix nesting Router
at /
leading to double slash in the path
#691
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this will be supported while .nest("", /* router */)
panics? That seems inconsistent to me.
We could make nesting at |
Yeah I think it would make sense for both to behave the same way, whether it works the same as In terms of implementation, wouldn't it be simpler to just delegate |
Done!
I thought so as well but the behavior regarding fallbacks is slightly different between the two. |
You didn't push though 😅 |
whoops! |
- **fixed:** Fix using incorrect path prefix when nesting `Router`s at `/` ([#691]) - **fixed:** Make `nest("", service)` work and mean the same as `nest("/", service)` ([#691]) - **fixed:** Replace response code `301` with `308` for trailing slash redirects. Also deprecates `Redirect::found` (`302`) in favor of `Redirect::temporary` (`307`) or `Redirect::to` (`303`). This is to prevent clients from changing non-`GET` requests to `GET` requests ([#682]) [#691]: #691 [#682]: #682
- **fixed:** Fix using incorrect path prefix when nesting `Router`s at `/` ([#691]) - **fixed:** Make `nest("", service)` work and mean the same as `nest("/", service)` ([#691]) - **fixed:** Replace response code `301` with `308` for trailing slash redirects. Also deprecates `Redirect::found` (`302`) in favor of `Redirect::temporary` (`307`) or `Redirect::to` (`303`). This is to prevent clients from changing non-`GET` requests to `GET` requests ([#682]) [#691]: #691 [#682]: #682
Just as an info: base: Router::new()
.nest("/", pages::routes())
Router::new()
.route("/", get(index))
.route("something/:id", get(something))
.route("other", post(other))
Router::new()
.route("/", get(index))
.route("/something/:id", get(something))
.route("/other", post(other)) |
If you nested a
Router
at/
the path for the final routes would start with a double slash.Fixes #690
Aside about how nesting works:
When you nest a service we try and downcast it to a
Router
. If that succeeds we simply move all the paths from one router onto another, with the path prefix added plus a middleware that strips the prefix before calling theMethodRouter
. That simplifies lots of things internally because there is only one router that has all the paths. It also improves performance since matchit can see the entire tree. If the downcast fails we just nest it as an opaque service however, don't really have other options.This is why nesting a
Router
at/
is fine, and wont collide with all other routes, but nesting something likeServeDir
will.