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

What Nested Routes Are and Why They Matter

Understanding how nested routes let you compose layouts and share UI elements across different URL segments.

What Nested Routes Are and Why They Matter

You'll learn how nested routes let you build hierarchical UIs where different URL segments control different parts of your layout.

The Core Concept

Nested routes allow you to embed routes within other routes, creating a parent-child relationship that mirrors your URL structure. Instead of defining every route as a standalone page, you can compose layouts where parent routes render common UI elements (like headers, sidebars, or tabs), while child routes render content that changes based on the URL.

Think of it like a Russian nesting doll for your UI: the outermost doll (parent route) stays visible, but as you open each layer, you reveal different inner dolls (child routes) depending on which part of the URL you're visiting.

Why This Matters

Without nested routes, you'd need to duplicate layout code across multiple pages. Imagine an app with a dashboard at /dashboard that shows a sidebar and tabs. You want /dashboard/profile, /dashboard/settings, and /dashboard/analytics to all share that same sidebar, but display different content in the main area.

Nested routes solve this elegantly: your /dashboard route renders the shared layout, and child routes render into a designated outlet within that layout. The URL structure (/dashboard/profile) naturally maps to your component hierarchy.

This pattern enables:

  • Code reuse: shared layouts without duplication
  • Predictable structure: URL paths mirror component nesting
  • Persistent UI: parent elements stay mounted while children swap
  • Contextual state: parent routes can provide context to all children

Key Takeaway: Nested routes let you compose layouts hierarchically, where parent routes provide shared UI and children render different content based on URL segments—eliminating duplication and creating intuitive URL-to-UI mappings.