Layouts: The Backbone of Next.js App Router
In the App Router, layouts are persistent components that wrap pages and preserve state during navigation. Understanding how they compose is essential for building efficient applications.
Learning Objectives
Lesson Outline
In the App Router, layouts are persistent components that wrap pages and preserve state during navigation. Understanding how they compose is essential for building efficient applications.
When rendering /dashboard/analytics, Next.js composes:
| Layout | Template |
|---|---|
| Persists state between navigations | Creates new instance on every navigation |
| Does not re-mount | Re-mounts on every route change |
| Use for: sidebars, navbars, shared UI | Use for: analytics, animations, per-page effects |