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

Clarify some subtleties of routing #2896

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion axum/src/docs/routing/fallback.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ async fn fallback(uri: Uri) -> (StatusCode, String) {

Fallbacks only apply to routes that aren't matched by anything in the
router. If a handler is matched by a request but returns 404 the
fallback is not called.
fallback is not called. Note that this applies to [`MethodRouter`]s too: if the
request hits a valid path but the [`MethodRouter`] does not have an appropriate
method handler installed, the fallback is not called (use
[`MethodRouter::fallback`] for this purpose instead).


# Handling all requests without other routes

Expand Down
5 changes: 5 additions & 0 deletions axum/src/docs/routing/nest.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ let app = Router::new()
# let _: Router = app;
```

Additionally, while the wildcard route `/foo/*rest` will not match the
paths `/foo` or `/foo/`, a nested router at `/foo` will match the path `/foo`
jplatte marked this conversation as resolved.
Show resolved Hide resolved
(but not `/foo/`), and a nested router at `/foo/` will match the path `/foo/`
Comment on lines +86 to +87
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm skeptical about a different bit here: A nested router at /foo will not match /foo/ (first parenthesis)? I'm pretty sure that's not right.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn’t you open #2659 which explains this behaviour?
ts
nots

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely forgot 🫠

Guess I am still of the same opinion, this is super confusing and should be changed. Makes it even more important to have clear docs!

(but not `/foo`).

# Fallbacks

If a nested router doesn't have its own fallback then it will inherit the
Expand Down