Skip to content
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 fallback handlers on nested routers returning 404 #2524

Closed

Conversation

dalton-oliveira
Copy link

@dalton-oliveira dalton-oliveira commented Jan 16, 2024

Motivation

The issue #2252 ia about a breaking change on fallback action of a nested Router. Previously, if the nested Router with a fallback is matched, it should call it's fallback when the route is not defined. Example:

https://github.com/dalton-oliveira/axum/blob/1313119b73663ea1f6e461197195ad89248b6e83/axum/src/routing/tests/nest.rs#L387-L397

This breaking change was introduced once it started to use matchit for routing to the fallback handler. It uses a special catch-all-parameter /*__private__axum_fallback which does't match empty path which would be the root of the nested router. There's no option for matching zero-or-more pattern. There's an open issue Support optional last param that, once solved, I think would be sufficient for this scenario and thus a better solution too.

Solution

This changes Router::nest to also nest the root for the fallback PathRouter

Fixes #2252

@dalton-oliveira dalton-oliveira changed the title fix nested fallback actionalble also on nested root fix nested fallback actionable also on nested root Jan 16, 2024
@dalton-oliveira dalton-oliveira mentioned this pull request Jan 16, 2024
1 task
@dalton-oliveira dalton-oliveira force-pushed the fix/fallback_with_tsr branch 3 times, most recently from 6a4325c to 6310b3a Compare January 17, 2024 00:42
@dalton-oliveira dalton-oliveira changed the title fix nested fallback actionable also on nested root Fix fallback handlers on nested routers returning 404 Jan 18, 2024
@dalton-oliveira dalton-oliveira marked this pull request as draft February 1, 2024 12:15
@dalton-oliveira
Copy link
Author

Closing as it wasn't completely fixing the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fallback handlers on nested routers returning 404
1 participant