g route and doesn't have its own fallback it will call the fallback from the outer router, i.e. the `fallback` function. If the nested router has its own fallback then the outer fallback will not be inherited: ```rust use axum::{ routing::get, http::StatusCode, handler::Handler, Json, Router, }; async fn fallback() -> (StatusCode, &'static str) { (StatusCode::NOT_FOUND, "Not Found") } async fn api_fallback() -> (StatusCode, Json) { ( StatusCode::NOT_FOUND, Json(serde_json::json!({ "status": "Not Found" })), ) } let api_routes = Router::new() .route("/users", get(|| async {})) .fallback(api_fallback); let app = Router::new() .nest("/api", api_routes) .fallback(fallback); # let _: Router = app; ``` Here requests like `GET /api/not-found` will go to `api_fallback`. # Nesting routers with state When combining [`Router`]s with this method, each [`Router`] must have the same type of state. If your routers have different types you can use [`Router::with_state`] to provide the state and make the types match: ```rust use axum::{ Router, routing::get, extract::State, }; #[derive(Clone)] struct InnerState {} #[derive(Clone)] struct OuterState {} async fn inner_handler(state: State) {} let inner_router = Router::new() .route("/bar", get(inner_handler)) .with_state(InnerState {}); async fn outer_handler(state: State) {} let app = Router::new() .route("/", get(outer_handler)) .nest("/foo", inner_router) .with_state(OuterState {}); # let _: axum::Router = app; ``` Note that the inner router will still inherit the fallback from the outer router. # Panics - If the route overlaps with another route. See [`Router::route`] for more details. - If the route contains a wildcard (`*`). - If `path` is empty. [`OriginalUri`]: crate::extract::OriginalUri [fallbacks]: Router::fallback