Skip to main content
A layout file defines UI that is shared across multiple routes. Layouts persist across navigations and do not re-render when their child routes change.
app/dashboard/layout.js

Root layout

The app directory must include a root layout.js. The root layout defines the <html> and <body> tags and is applied to every route.
app/layout.js
Do not add <head> tags like <title> or <meta> directly in the root layout. Use the Metadata API instead, which handles streaming and deduplication automatically.

Props

React.ReactNode
required
The nested layout or page rendered by this layout segment. May also include other special files like loading.js or error.js when applicable.
Promise<object>
A promise that resolves to the dynamic route parameters from the root segment down to the current layout.
app/dashboard/[team]/layout.js
Use async/await or React’s use() to read the value.

TypeScript helper

Use the global LayoutProps helper to get strongly typed props, including params and named parallel route slots:
app/dashboard/layout.tsx
Types are generated during next dev, next build, or next typegen. LayoutProps is globally available and does not need to be imported.

Root layout requirements

  • Must define <html> and <body> tags
  • Must not add <head> tags directly — use the Metadata API instead
  • Can have multiple root layouts using route groups (e.g., app/(shop)/layout.js and app/(marketing)/layout.js)
  • Navigating between different root layouts causes a full page load (not client-side navigation)

Caveats

Request object

Layouts do not have direct access to the incoming request. Use the headers() and cookies() APIs from next/headers instead.
app/shop/layout.js

Query params

Layouts do not re-render on navigation, so searchParams in a layout would become stale. To access current query params, use the searchParams prop in a page, or use useSearchParams() in a Client Component.

Pathname

Layouts do not re-render on navigation. To access the current pathname, use usePathname() in a Client Component.

Fetching data

Layouts cannot pass fetched data directly to child pages. However, you can fetch the same data in both the layout and the page. Next.js automatically deduplicates fetch calls, so performance is not affected.

Examples

Exporting metadata

app/layout.js

Displaying content based on params

app/dashboard/[team]/layout.js

Reading params in a Client Component

Use React’s use() function to read the params promise in a Client Component:
app/page.js

Accessing child route segment

Use useSelectedLayoutSegment() or useSelectedLayoutSegments() in a Client Component to read the active route segment below the layout:
app/ui/nav-link.js
app/ui/nav-links.js

Version history