Fullstack CourseLearn by building
Back to week 3

Topic

Use layouts and pages

Definition

In the App Router, page.tsx defines route-specific content and layout.tsx defines shared UI that wraps a route segment and its descendants.

In simpler words

A page is the screen for one URL; a layout is the durable frame around related screens.

Choose the file that owns UI so navigation, providers, and page-specific data do not become tangled.

After this you can

  • Map page and layout files to a route
  • Choose page versus layout ownership
  • Use route groups to create separate shells

Compose shared frames

Layouts nest from the root down to the current segment. This makes them appropriate for shared navigation, application providers, and chrome that should survive a sibling navigation.

A page should own the content and data presentation specific to its route. Putting every page concern in a layout makes the shared frame difficult to reason about.

A layout wrapping a page

// app/course/layout.tsx (sketch)
export default function CourseLayout({ children }: { children: React.ReactNode }) {
  return <>{children}</>;
}

// app/course/[track]/page.tsx
export default function TrackPage() {
  return <TrackRoadmap />;
}

The navigation belongs to the shared shell; ticket content belongs to its page.

Mistake: fetching page-only data in a layout

// Wrong — every child route now depends on tickets
export default async function Layout() {
  const tickets = await getTickets();
  return <TicketList tickets={tickets} />;
}

// Right — fetch/render ticket-specific content in tickets/page.tsx

Layouts should not accidentally make sibling routes load unrelated data.

Keep providers intentional

Definition

A layout can provide stable context to its descendants, but a Client Component provider makes its subtree client-capable.

In simpler words

Place providers as low as their consumers allow.

Keep the root layout focused on document structure, global styles, and truly global providers.

Place interactive providers below server-rendered layout content when possible to preserve server boundaries.

Live playground

Layouts and pages playground

Move shared navigation between a page and layout, then predict which routes receive it.

layout.tsx (nav stays mounted)

page.tsx: Ticket list

Keep in mind

  • Put stable navigation in a layout.
  • Keep page-specific data and UI in page.tsx.
  • Use a route group when related pages need a different shell.

Test

Check your understanding

At least 10 questions — mix of concept, syntax, practical, and logic. Score ≥ 80% (enforced by the API) to save progress.

Checking your session…

10 questions · concept 3 · syntax 2 · practical 3 · logic 2

Concept1. Which statement is the most accurate definition of App Router layouts and pages?
Syntax2. Which code-level choice is consistent with App Router layouts and pages?
Practical3. A reviewer sees this situation. Which decision best applies App Router layouts and pages?
Logic4. What reasoning correctly explains why this approach works for App Router layouts and pages?
Concept5. Which boundary does the correct use of App Router layouts and pages preserve?
Practical6. What is the safest next step when implementing App Router layouts and pages?
Syntax7. Which implementation direction matches the rule for App Router layouts and pages?
Logic8. Which consequence follows from applying App Router layouts and pages correctly?
Concept9. Which claim about App Router layouts and pages is true in this monorepo?
Practical10. Which team practice best demonstrates App Router layouts and pages?