Skip to content
Learn Netverks

Lesson

Step 7/36 19% through track

layouts-nesting

Layouts and nesting

Last reviewed Jun 1, 2026 Content v20260601
Track mode
client_nextjs
Means
In-browser Next.js (client components)
Reading
~2 min
Level
intermediate

This lesson

This lesson teaches Layouts and nesting: the concepts, APIs, and habits you need before advancing in Next.js.

Without Layouts and nesting, you will struggle to read or extend Next.js codebases and playground exercises.

You will apply Layouts and nesting in contexts like: Marketing sites, dashboards, e-commerce, and Vercel-style deployments that need hybrid static + dynamic pages.

Write TSX for Client Components, click Run—React 18 CDN + in-browser TSX compile; use client/server lessons explain App Router concepts; mountApp renders interactive UI; printOutput feeds the terminal.

When you can explain the previous lesson's ideas without copying starter code.

Layouts wrap child routes and re-render only their {children} slot when navigating between siblings. That persistence is ideal for nav bars, sidebars, and shared context providers that should survive page changes.

Nested layout pattern

// app/layout.tsx — root
export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>{children}</body>
    </html>
  );
}

// app/dashboard/layout.tsx
export default function DashboardLayout({ children }: { children: React.ReactNode }) {
  return (
    <div className="dashboard-shell">
      <aside>Nav</aside>
      <main>{children}</main>
    </div>
  );
}

What persists vs remounts

  • Layout component state persists across sibling navigations under the same layout
  • page.tsx content swaps when the URL segment changes
  • template.tsx remounts on every navigation (use when you need a fresh effect each visit)

Important interview questions and answers

  1. Q: Can you nest multiple layouts?
    A: Yes—each folder can export a layout; they compose outward from root to leaf.
  2. Q: Where does shared auth UI belong?
    A: In a layout wrapping protected segments, or middleware redirecting before render.

Self-check

  1. Why is a sidebar usually in layout.tsx not page.tsx?
  2. When would you choose template.tsx over layout?

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Shared chrome pattern?
  • layout vs template?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump