Nested Routes

Last updated: 2026-11-02

Nested Routes Nested Routes

Nested routes express a layout plus its child pages as parent and child Route elements: a parent Route contains more Routes, and the parent component draws an Outlet slot where the matched child page is rendered. The classic admin layout - a fixed sidebar with a switching content area - is built entirely from this pattern. Each level keeps its own chrome, so even a deep hierarchy of layouts stays easy to reason about.

GroupRouting & State Mgmt
KindComponent
SinceReact Router 6.4

ℹ️ Info The editor transpiles JSX to JavaScript and renders the real UI in a sandbox; components mount automatically — no manual render call needed.

📝 Syntax

import { Routes, Route, Outlet } from 'react-router-dom'

function DashboardLayout() {
  return (
    <div>
      <aside>Sidebar (fixed by the parent)</aside>
      <main><Outlet /></main>   {/* the child route renders here */}
    </div>
  )
}

<Route path="dashboard" element={<DashboardLayout />}>
  <Route index element={<Overview />} />   {/* the default child page of /dashboard */}
  <Route path="team" element={<Team />} /> {/* /dashboard/team */}
</Route>

⚙️ Parameters

path (parent)The parent path segment; the path of a child Route is appended to it, while a leading / makes it absolute.
indexA special marker on a child Route: the default child page rendered when the parent path itself (e.g. /dashboard) has no further segments.

Returns:Nothing (it is a declarative component). The parent route renders its own element, and the position of the Outlet inside it decides where the child route content appears.

▶ Example

The example runs out of the box: it auto-renders when expanded, and edits take effect instantly.

Output:

The outer frame and the title (the parent layout) never change, while the dashed box (the Outlet position) switches child pages as you click - the rendering result of nested parent/child Routes plus Outlet (simulated demo).

💡 Key Points

💡 Tip The index route answers "what should show when I visit /dashboard itself": it gives the parent path a default page, rendered by the Outlet of the parent layout.
ℹ️ Info A child path without a leading slash is appended relatively (path='team' -> /dashboard/team), while a leading / counts from the root; the relative form is easier to maintain when you rearrange the hierarchy.
⚠️ Warning If the parent component forgets the Outlet, a matched child route renders nothing - an empty content area is the most common symptom of this mistake.
More case studies coming soon.

📚 Related Tutorials

❓ FAQ

Q What is an Outlet?
A The rendering placeholder of a child route. Think of it as a hole dug in the parent component: the element of the matched child Route is filled into it, and Outlets can be nested as deep as you like.
Q Why is /dashboard empty?
A Because no child route matched. Add an index child Route to the parent route to provide a default page.
Q Can child routes be nested even further?
A Yes. Outlets nested inside Outlets build a layout tree of any depth, and each parent level owns its own fixed shell.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏