Advertisement
Beginner Next.js, Layouts & Templates

What is a layout in the Next.js App Router, and how does it work?

Short answer

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.

Save Next.js mock interview
Advertisement
AModel answer
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.
Likely follow-ups
  • Does a layout re-render every time you navigate between nested pages?
  • Can you nest multiple layouts inside each other?
Related topics