Maaz Zindani

Loading the index…

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

Clicking a React Router Link changes the URL but the new page stays blank

ErrorThe URL changes to /dashboard/settings but the page still shows the old content

Short answer

The URL change proves the Link works and the router matched a route. What is missing is a place to draw the match. A nested route renders only where its parent puts an Outlet, and an index route cannot have children. Check those two first, then that every Route sits inside Routes.

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

Fix it fast

  1. 1Find out which cause you have

    Print the router's current location inside the layout that should show the child. If the pathname changes while nothing renders below it, the route matched and the problem is where it is drawn.

    import { useLocation } from 'react-router';
    
    function Dashboard() {
      const location = useLocation();
      console.log(location.pathname);
      return <h1>Dashboard</h1>;
    }
  2. 2Match what you see, then jump to its fix

    1. 1Parent content renders, the child component is missing, the console is cleanThe parent route has no OutletFix
    2. 2A Route with the index prop contains child Route elementsThe child route is nested inside an index routeFix
    3. 3Route elements are written directly inside a component or Fragment, with no Routes element around themA Route is not rendered inside RoutesFix

What does the error look like?

  • The URL changes to /dashboard/settings but the page still shows the old content
  • The parent layout renders, the child is missing
  • No error in the console

Cause 1 of 3

The parent route has no Outlet

1Check

React Router's docs say child routes render through the Outlet in the parent route, and that Outlet renders the matching child route or nothing. A parent element without it has nowhere to show the child.

grep -rLn "<Outlet" src/layouts src/pages

2Fix

Render an Outlet in the parent's element at the place the child should appear.

import { Outlet } from 'react-router';

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

3Verify

Click the Link again. The child appears under the heading.

npm run dev

Confirmed by reactrouter.com

Did this fix it?

Cause 2 of 3

The child route is nested inside an index route

1Check

The routing guide states that index routes cannot have children. Children placed inside one are never rendered.

grep -rnE "<Route index" src

2Fix

Move the children to a layout route: a Route without a path adds nesting without adding a URL segment.

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

3Verify

Visit /dashboard/settings. The Settings component renders inside Dashboard's Outlet.

console.log(window.location.pathname); // /dashboard/settings

Confirmed by reactrouter.com

Did this fix it?

Cause 3 of 3

A Route is not rendered inside Routes

1Check

The Route reference states that a Route must be rendered within a Routes element. Check the component that holds your Route elements.

grep -rnE "<Routes|<Route " src

2Fix

Wrap the Route elements in Routes, inside the BrowserRouter.

<BrowserRouter>
  <Routes>
    <Route path="/" element={<App />} />
  </Routes>
</BrowserRouter>

3Verify

Click the Link. The route's element mounts.

console.log(window.location.pathname);

Confirmed by reactrouter.com

Did this fix it?

How do I stop it coming back?

  • Give every parent route element an Outlet as part of writing the layout.
  • Use a pathless layout route when you need nesting without a URL segment.
  • Add a test that navigates to each nested URL and checks the child text is on screen.

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.