Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Child routes in React Router do not render inside the parent page

ErrorThe parent layout renders but the child page is empty

Short answer

A child route does not appear by itself. The parent route's component must render an Outlet, which is where React Router places the matching child. Also check that child paths are relative (no leading slash), and that the parent has an index route for the bare parent URL.

  • Applies to React Router 6.30, React Router 7, React 19
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open the component used as the parent route's element and search it for Outlet. If it is not there, the first cause is yours.

    grep -rn "Outlet" src/
  2. 2Match what you see, then jump to its fix

    1. 1The parent page shows, the URL is the child's URL, the child area is blankThe parent component does not render an OutletFix
    2. 2The child only renders at a doubled URL such as /dashboard/dashboard/settingsThe child path repeats the parent or starts with a slashFix
    3. 3/dashboard shows the layout with an empty content areaNothing is defined for the bare parent URLFix

What does the error look like?

  • The parent layout renders but the child page is empty
  • The URL changes to /dashboard/settings and nothing else changes on screen

Cause 1 of 3

The parent component does not render an Outlet

1Check

The docs say child routes are rendered through the Outlet in the parent route. A parent element without one has nowhere to put the child.

grep -n "Outlet" src/pages/Dashboard.jsx

2Fix

Import Outlet and place it where the child should appear.

import { Outlet } from "react-router-dom";

export default function Dashboard() {
  return (
    <div>
      <h1>Dashboard</h1>
      <Outlet />
    </div>
  );
}

3Verify

Open /dashboard/settings. The heading and the settings page both show.

npm run dev

Confirmed by reactrouter.com

Did this fix it?

Cause 2 of 3

The child path repeats the parent or starts with a slash

1Check

The parent's path is automatically included in the child, so a child written as dashboard/settings under a dashboard parent doubles the segment.

grep -rn "<Route" src/

2Fix

Write the child path relative to its parent.

<Routes>
  <Route path="dashboard" element={<Dashboard />}>
    <Route index element={<Home />} />
    <Route path="settings" element={<Settings />} />
  </Route>
</Routes>

3Verify

Both /dashboard and /dashboard/settings match a route.

npm run dev

Confirmed by reactrouter.com

Did this fix it?

Cause 3 of 3

Nothing is defined for the bare parent URL

1Check

An index route renders into its parent's Outlet at the parent's URL. Without one, the outlet is empty there.

grep -n "index" src/App.jsx

2Fix

Add an index route as the default child. Index routes cannot have children of their own; use a layout route for that.

<Route path="dashboard" element={<Dashboard />}>
  <Route index element={<Home />} />
</Route>

3Verify

Open /dashboard and confirm that Home renders inside the layout.

npm run dev

Confirmed by reactrouter.com

Did this fix it?

How do I stop it coming back?

  • Give each layout component an Outlet the moment you create it.
  • Use relative child paths and an index route in every parent.
  • Keep the route tree in one file so the nesting is visible.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.