{"record":{"id":"e973b1775e0d1ced","repo":"leptos-rs/leptos","slug":"flatroutes-should-not-be-used-with-nested-routes","errorCode":null,"errorMessage":"<FlatRoutes> should not be used with nested routes.","messagePattern":"<FlatRoutes> should not be used with nested routes\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"router/src/flat_router.rs","lineNumber":138,"sourceCode":"        // release URL lock\n        drop(current_url);\n\n        match new_match {\n            None => Rc::new(RefCell::new(FlatRoutesViewState {\n                view: fallback().into_any().build(),\n                id,\n                owner,\n                params,\n                path,\n                url,\n                matched,\n            })),\n            Some(new_match) => {\n                let (view, child) = new_match.into_view_and_child();\n\n                #[cfg(debug_assertions)]\n                if child.is_some() {\n                    panic!(\n                        \"<FlatRoutes> should not be used with nested routes.\"\n                    );\n                }\n\n                let mut view = Box::pin(owner.with(|| {\n                    provide_context(params_memo);\n                    provide_context(url.clone());\n                    provide_context(Matched(ArcMemo::from(matched.clone())));\n\n                    ScopedFuture::new(async move {\n                        OwnedView::new(view.choose().await)\n                    })\n                }));\n\n                match view.as_mut().now_or_never() {\n                    Some(view) => Rc::new(RefCell::new(FlatRoutesViewState {\n                        view: view.into_any().build(),\n                        id,","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/router/src/flat_router.rs#L120-L156","documentation":"The <FlatRoutes> router component only supports flat route structures (no nested child routes). During match building, if a matched route definition produces a child route, the router panics in debug builds because the flat matcher cannot correctly render nested layouts.","triggerScenarios":"Using <FlatRoutes> with a route tree where any route has children — e.g. a parent route like \"/admin\" containing child routes, or nest( Parent, [children]) style definitions inside FlatRoutes instead of <Routes>.","commonSituations":"Migrating an existing <Routes> app to <FlatRoutes> for its simpler matching without flattening the route definitions; copying nested route examples into a FlatRoutes component; accidentally nesting routes via layout wrappers.","solutions":["Flatten the route definitions so every route is a single segment-free full path with no children, or use explicit full paths for each leaf.","Switch from <FlatRoutes> back to <Routes>, which fully supports nested routes.","Audit route definitions for children fields / nested route arrays and remove them when keeping FlatRoutes."],"exampleFix":"// before\n<FlatRoutes>\n  <Route path=\"admin\" view=AdminLayout>\n    <Route path=\"users\" view=Users/> // nested -> panic\n  </Route>\n</FlatRoutes>\n\n// after\n<Routes>\n  <Route path=\"admin\" view=AdminLayout>\n    <Route path=\"users\" view=Users/>\n  </Route>\n</Routes>\n// or flat: <FlatRoutes><Route path=\"admin/users\" view=Users/></FlatRoutes>","handlingStrategy":"validation","validationCode":"// assert no route in the tree has children before using FlatRoutes\nfn routes_are_flat(routes: &[RouteDef]) -> bool { routes.iter().all(|r| r.children.is_empty()) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run the app in debug mode during development so the invariant fails at build/render time, not in production.","Test navigation to every route, not just the initial URL.","Choose Routes when the route tree is or may become nested."],"tags":["leptos","leptos-router","flat-routes","nested-routes","panic"],"backgroundTag":"flat-routes-nested-routes","analyzedSha":"32d20f6c9d517451d77beb68d88c7716823dac41","analyzedAt":"2026-09-01T18:55:42.580Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}