Nested routes in React Router let one route render inside another, so a shared layout stays mounted while child pages swap into an Outlet. A parent route owns a URL prefix, and its children add segments after it. This guide builds a dashboard where /dashboard and /dashboard/settings share one frame.
Set up the parent route
The parent route carries the layout and the URL prefix. Give it a path and an element, then nest child routes inside it.
<Routes>
<Route path="dashboard" element={<Dashboard />}>
<Route index element={<Overview />} />
<Route path="settings" element={<Settings />} />
</Route>
</Routes>The child paths are relative. A child with path settings becomes /dashboard/settings, and the index route renders Overview at /dashboard itself. The index route is the default child for the parent's own path.
This single config produces two URLs from three routes.
A parent can also use a layout route with no path when the frame should not change the URL. That pattern appears in the React Router tutorial.
Render the child with Outlet
The parent has to say where child content appears. Put an Outlet in the Dashboard component, and React Router renders the matching child there.
import { Outlet } from "react-router";
export default function Dashboard() {
return (
<div>
<h1>Dashboard</h1>
<Outlet />
</div>
);
}When the URL is /dashboard, Overview renders inside the Outlet. When it is /dashboard/settings, Settings renders there instead, and the h1 stays put. The layout mounts once, so shared state inside Dashboard survives page changes.
This is the same Outlet idea used by layout routes, applied to a route that owns a URL prefix.
Link between nested pages
Inside a nested page, links can be relative to the parent route. A Link to settings resolves to /dashboard/settings because the current route is /dashboard.
import { Link } from "react-router";
export default function DashboardNav() {
return (
<nav>
<Link to="overview">Overview</Link>
<Link to="settings">Settings</Link>
</nav>
);
}A leading slash would make the link absolute, so to="/settings" would target /settings instead. Keep child links relative while you are inside the parent.
How the URL builds up
The final paths come from joining the parent prefix with each child path.
- /dashboard matches the parent route and renders the index child Overview.
- /dashboard/settings matches the settings child and renders it in the same Outlet.
- /dashboard/anything-else matches nothing unless you add another child route.
Nest another level
Nesting is recursive. Give a child route its own children and its own Outlet, and the URL keeps gaining segments. When a child needs a changing value in the URL, add a parameter to the child path, which dynamic routes and URL parameters explains.
Each level only needs an Outlet in the component that owns the child routes.
Common mistakes
- Forgetting Outlet in the parent, so child pages never appear.
- Giving a child an absolute path, which breaks the shared prefix.
- Repeating the layout in every child instead of the parent.
Rune AI
Key Insights
- Nest child Route elements inside a parent Route.
- Render the matching child with Outlet in the parent.
- Use relative child paths so the parent prefix is preserved.
- Add an index route for the parent's own path.
Frequently Asked Questions
What is an index route?
Are child paths absolute or relative?
Do I need an Outlet in every parent?
Conclusion
Nested routes keep a shared layout mounted while child pages swap inside an Outlet. Give the parent a path and an element, nest child routes with relative paths, and add an index route for the parent's own URL.
More in this topic
How to Build a Dropdown Menu in React
Build a React dropdown menu with the ARIA menu button pattern. Handle open and close, keyboard arrows, and clicks outside the menu.
How to Animate React Components with Motion
Animate React components with the Motion library. Set up motion, add enter, hover, and exit animations, and respect reduced motion.
Headless UI Components Explained: Logic Without Locked Styling
Understand headless UI components and how libraries like Radix give you unstyled, accessible behavior that you style yourself.