diff --git a/axum/src/docs/routing/merge.md b/axum/src/docs/routing/merge.md index b8817513..4036df6b 100644 --- a/axum/src/docs/routing/merge.md +++ b/axum/src/docs/routing/merge.md @@ -1,4 +1,4 @@ -Merge two routers into one. +Merge the paths and fallbacks of two routers into a single [`Router`]. This is useful for breaking apps into smaller pieces and combining them into one. @@ -71,6 +71,11 @@ let app = Router::new() # let _: axum::Router = app; ``` +# Merging routers with fallbacks + +When combining [`Router`]s with this method, the [fallback](Router::fallback) is also merged. +However only one of the routers can have a fallback. + # Panics - If two routers that each have a [fallback](Router::fallback) are merged. This diff --git a/axum/src/routing/tests/merge.rs b/axum/src/routing/tests/merge.rs index cc656289..44b0ce8d 100644 --- a/axum/src/routing/tests/merge.rs +++ b/axum/src/routing/tests/merge.rs @@ -135,6 +135,8 @@ async fn layer_and_handle_error() { let res = client.get("/timeout").send().await; assert_eq!(res.status(), StatusCode::REQUEST_TIMEOUT); + let res = client.get("/foo").send().await; + assert_eq!(res.status(), StatusCode::OK); } #[crate::test]