Skip to main content

Layout Routes

Layout routes (also called “pathless routes”) are routes that provide shared UI structure for child routes without adding segments to the URL. They’re perfect for shared navigation, authentication layouts, and grouping routes with common UI.

Basic Layout Routes

Use the layout() helper to create a layout route:
URL structure:
  • /dashboard → renders app-layout.tsx with dashboard.tsx in the outlet
  • /profile → renders app-layout.tsx with profile.tsx in the outlet
  • /settings → renders app-layout.tsx with settings.tsx in the outlet
No /app-layout URL is created.

Layout Component

Layout routes must render an <Outlet /> for child routes:

Multiple Layout Routes

Create different layouts for different sections of your app:

Nested Layout Routes

Layout routes can be nested for hierarchical UI structures:
URL /account/profile renders:
  1. app-layout.tsx
  2. account/layout.tsx (in first outlet)
  3. → → account/profile.tsx (in second outlet)

File-Based Layout Routes

When using flatRoutes(), prefix route names with _ to create layout routes:
The leading _ indicates a pathless layout route.

Layout with Shared Data

Load shared data in layout routes:
Child routes can access this data with useMatches():

Authentication Layout

Protect routes with an auth layout:

Layout with Context

Pass data to child routes via outlet context:

Conditional Layouts

Apply different layouts based on conditions:

Pathless Routes with Paths

Combine layout routes with path-based parent routes:
URLs:
  • /account/login → account.tsx > public-layout.tsx > login.tsx
  • /account/profile → account.tsx > private-layout.tsx > profile.tsx

Layout Error Boundaries

Handle errors in layout routes:

Layout Actions

Handle form submissions in layouts:

Common Patterns

Marketing + App Split

Role-Based Layouts

Multi-Step Forms

Best Practices

  1. Shared UI only: Use layouts for shared UI elements (nav, header, footer)
  2. Minimal data loading: Only load data needed by the layout itself
  3. Clear naming: Name layout files descriptively (e.g., app-layout.tsx, auth-layout.tsx)
  4. Error boundaries: Add error boundaries to layouts for better error handling
  5. Avoid deep nesting: Keep layout nesting to 2-3 levels maximum
  6. Context over props: Use outlet context for passing data to all children