Sikau

Next.js · Day 3 · about 25 min

Layouts

Shared UI that wraps pages and keeps its state.

Write the header once

Every page needs the same header, navigation and footer. A layout wraps all pages in its folder (and below). When you navigate, the layout stays put — only the page inside changes.

layout.jsx receives children

export default function MenuLayout({ children }) {
  return (
    <section>
      <h2>Our menu</h2>
      <p className="note">All prices include tax.</p>
      {children}
    </section>
  );
}
  • Layouts nest: root layout → menu layout → page.
  • The root app/layout.jsx is required and must render <html> and <body>.
  • Layouts don't re-render on navigation between their pages, so state inside them (like an open sidebar) survives.

The rest of this lesson

  • Why layouts persistexplain
  • What belongs in a layoutexplain
  • Nesting orderpredict
  • Outer to innerorder
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 19 lessons of Next.js