Fix fallback handlers on nested routers returning 404 #2524
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
The issue #2252 ia about a breaking change on
fallback
action of a nestedRouter
. Previously, if the nestedRouter
with afallback
is matched, it should call it'sfallback
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 matchingzero-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 thefallback
PathRouter
Fixes #2252