0
Challenge · 44Routing & Data
Layout Routes
Coreused in ~70% of apps
Every page in your app shares the same nav, sidebar, and footer — and you do NOT want to import and re-render them on every screen. A layout route lets one parent render the shared shell once, with a hole where each child page slots in.
Core idea. A layout route is a parent route — often with no path of its own — whose element renders the shared UI plus an <Outlet/>; React Router renders the matched child route into that Outlet, so the layout persists while only the inner content swaps. An index route (index: true) is the child that fills the Outlet when the URL is exactly the parent's path.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
route config
createBrowserRouter([
{ path: "/app", element: <AppLayout/>,
children: [
]
}
]);
Click a child route to "navigate". The pathless parent (<AppLayout/>) wraps every child.
example.com/app
layout mounted 1×
AppLayout
sidebar (layout)
This input lives in the layout. Switch tabs — your text stays.
<Outlet /> contentchild mounted 1× (fresh)
Dashboardindex: true
The index route — shown by default when the URL is exactly the parent path.
The pathless <AppLayout/> mounts once and stays put — only the <Outlet/> swaps as you navigate. Your sidebar text and the layout mounted 1× badge prove it. With no child segment, the index route fills the Outlet.
↑ play a little first, then dig in