- All Courses
- Next.js for Production
- Routing and Layouts in the App Router
- Nested layouts and templates
Nested layouts and templates
A layout wraps its segment and every route nested below it.
Overview
Layouts persist, templates do not
A layout wraps its segment and every route nested below it. On navigation between sibling routes, the layout instance is preserved: its state survives, its effects do not re-run, and only the segment below it swaps out. That is what makes a persistent sidebar or a media player possible.
A template looks identical but remounts on every navigation. Reach for it when you specifically want that reset — an entry animation that should replay, or a form that must clear between records.
Layouts nest, so a route inherits every layout above it. The root layout is special: it owns the html and body tags and is the one layout that cannot be skipped.
If you find yourself fighting a layout to reset state, you probably wanted a template.
In this lesson you will:
- Share chrome across routes without re-rendering it
- Choose between a layout and a template
- Preserve state across navigations inside a layout
Resources
Notes are not saved yet — they clear when you leave this page.
App Router file conventions
6m
Dynamic segments and route parameters
5m