Next.js › Layouts & Templates
What is a layout in the Next.js App Router, and how does it work?
BeginnerAnswer
A layout is a component defined in a layout.js file that wraps a page and any of its nested pages, letting you share common user interface elements like a navigation bar or sidebar across multiple pages without repeating that code in every single page file.
// app/dashboard/layout.js
export default function DashboardLayout({ children }) {
return (
<div>
<Sidebar />
<main>{children}</main>
</div>
);
}Real-world example A dashboard application shares the same sidebar and header across every dashboard page by placing them in a single layout file, avoiding repeated code across dozens of individual pages.