Clarify some subtleties of routing (#2896)

This commit is contained in:
Sabrina Jewson 2024-09-22 12:32:59 +01:00 committed by Jonas Platte
parent a73dab417d
commit 6ec3a51f2d
No known key found for this signature in database
GPG key ID: 7D261D771D915378
2 changed files with 10 additions and 1 deletions

View file

@ -23,7 +23,11 @@ async fn fallback(uri: Uri) -> (StatusCode, String) {
Fallbacks only apply to routes that aren't matched by anything in the 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 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 # Handling all requests without other routes

View file

@ -82,6 +82,11 @@ let app = Router::new()
# let _: Router = app; # 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`
(but not `/foo/`), and a nested router at `/foo/` will match the path `/foo/`
(but not `/foo`).
# Fallbacks # Fallbacks
If a nested router doesn't have its own fallback then it will inherit the If a nested router doesn't have its own fallback then it will inherit the