Course contentsShow
← React
Lesson 1835 of 2,39643. RoutingFree lesson

Path Construction in Nested Routes

How child route paths combine with parent paths, and when to use relative vs absolute paths.

Path Construction in Nested Routes

You'll learn how React Router combines parent and child paths to build complete URLs, and when to use relative versus absolute paths.

How Paths Combine

When you nest routes, React Router automatically constructs the full path by concatenating parent and child paths. If your parent route has path "/dashboard" and a child route has path "settings", the resulting URL is "/dashboard/settings". The child path is relative to its parent by default.

Think of it like a file system: if you're in the /home/user directory and reference documents, the full path becomes /home/user/documents. You're building on top of where you already are.

Relative Paths (Default)

<Route path="/dashboard" element={<DashboardLayout />}>
  <Route path="settings" element={<Settings />} />
  <Route path="profile" element={<Profile />} />
</Route>

Here, "settings" (no leading slash) is relative. The full paths become:

  • /dashboard/settings
  • /dashboard/profile

Absolute Paths

If a child path starts with /, it's absolute and ignores the parent path:

<Route path="/dashboard" element={<DashboardLayout />}>
  <Route path="/admin" element={<Admin />} />
</Route>

Now the child route is accessible at /admin, completely independent of /dashboard. This breaks the nesting hierarchy in terms of URL structure (though the component still renders through the parent's <Outlet />).

When to Use Each

Use relative paths (99% of cases) when the child logically belongs under the parent in your URL structure. Use absolute paths rarely, when you need to escape the parent's path for architectural reasons while maintaining the component hierarchy.

Key Takeaway: Child route paths are relative by default, concatenating with parent paths. Only use absolute paths (with leading /) when you explicitly need to break out of the parent's URL namespace.