Nested layouts
Layouts in the folder hierarchy nest by default. Each layout wraps the
layouts and pages below it through its children prop, so shared chrome is
composed layer by layer.
To add a layout for a route, drop a layout file inside that route segment's
folder:
// app/blog/layout.tsx
export default function BlogLayout({ children }: { children: React.ReactNode }) {
return <section>{children}</section>;
}
With the root layout in app/layout.tsx and this one in app/blog/layout.tsx,
the root layout wraps the blog layout, which in turn wraps the pages beneath
/blog — app/blog/page.tsx and the dynamic app/blog/[slug]/page.tsx:
app/
layout.tsx # root layout (wraps everything)
blog/
layout.tsx # nested layout (wraps the /blog routes)
page.tsx # /blog
[slug]/
page.tsx # /blog/[slug]
Because the root layout stays mounted as you move between /blog and a post,
its state is preserved and it does not rerender. Each nested layout only needs
to describe the chrome for its segment.
You are about to answer a short quiz on nested layouts and route segments.