Skip to main content
Nested layouts allow you to create hierarchical UI structures where parent routes wrap child routes, enabling shared layouts, navigation, and state across route segments.

Basic nested layouts

Use the Outlet component to render child routes:

File-based layout structure

Organize layouts using file structure:

Pathless layouts

Create layouts that don’t add to the URL path using _ prefix:
src/routes/_auth.tsx

Multiple layout levels

Nest layouts within layouts:

Layout with shared data

Load data in parent and access in children:
src/routes/dashboard.tsx
src/routes/dashboard/settings.tsx

Layout context

Share state between parent and child routes:
src/routes/dashboard.tsx
Highlight active navigation items:

Layout groups

Group routes without affecting the URL:

Conditional layouts

Render different layouts based on conditions:

Pending states in layouts

Show loading states while child routes load:

Best practices

Layouts should focus on structure and shared UI, not business logic.
Wrap protected routes in pathless layouts for clean URLs.
Avoid duplicate data fetching by loading once in the layout.
Use React Context for sharing state between layouts and children.

Next steps

Data loading

Share data between layouts

Routes concept

Deep dive into route configuration