Nested layouts
A nested layout wraps only the route subtree beneath its folder. Use it when several nearby pages share navigation or a section heading but the rest of the site should not inherit that UI.
Scope: Next.js 16.x candidate, App Router only, Cache Components disabled, TypeScript unless otherwise labeled. Examples are static source walkthroughs; exact framework patch and build are not verified.
app/catalog/layout.tsx
import type { ReactNode } from 'react';import Link from 'next/link';export default function CatalogLayout({ children }: { children: ReactNode }) { return <section aria-label="Book catalog"> <nav aria-label="Catalog"><Link href="/catalog">All books</Link>{' | '}<Link href="/catalog/moss">Moss</Link></nav> {children} </section>;}The catalog navigation is expected on /catalog and /catalog/moss, but not /help. The root layout still surrounds both areas.
Trace the wrappers
Folder ancestry determines which layouts apply. A nested layout does not replace the root; it is placed inside its parent layout. Put a unique title or item-specific data in a page, not in a section wrapper. The book detail route is introduced in chapter 7; it is a planned destination in this preview.
Folder tree and expected wrappers
app/ layout.tsx catalog/ layout.tsx page.tsx [slug]/page.tsx help/page.tsx/catalog/moss: root → catalog layout → detail page. /help: root → help page. The catalog layout by itself does not create an index page.
Common mistake
Do not add html/body to the catalog layout while it has a parent root layout. Do not rely on a nested layout to provide authorization for every request; enforce access where protected data is used.
Try it yourself
Design a layout for /account/profile and /account/settings that is absent from /catalog. Draw the wrapper tree for all three URLs.
After this lesson, you should be able to: Map a nested wrapper to its descendants; Choose shared versus page-specific UI.