Course map
Stage 1: App Router Foundations
Stage 2: The Rendering Model
Stage 3: Data, Caching and Mutations
Stage 4: Full-Stack Next.js
Stage 5: Production and Specialization

Part 03 / Topic 1 of 7

A nested layout for the whole storefront

Part 2 built six routes under /store with no file wrapping any of them — every page was "a single page.tsx file with nothing wrapping it," on purpose, because layout.tsx was deliberately deferred to this part. That deferral ends here. A layout is UI shared between multiple pages: you define it by default-exporting a component that accepts children from a layout.tsx file, and the installed package's own getting-started guide is explicit about the payoff — "On navigation, layouts preserve state, remain interactive, and do not rerender."

harness/app/store/layout.tsx wraps every route under /store — both the storefront pages and the about/contact pages — in one shared navigation bar:

import { StoreNav } from "./_components/StoreNav";

export default function StoreLayout({ children }: { children: React.ReactNode }) {
  return (
    <>
      <StoreNav />
      {children}
    </>
  );
}

StoreNav is a Client Component (section 5 covers why), colocated in a private _components folder — the same underscore convention Part 2's section 7 used for _draft, reused here for its intended purpose: a folder that holds code, not a route, and is guaranteed never to become one.

Nesting still works exactly like Part 2's folder-to-URL nesting: the root layout (app/layout.tsx, Part 1) wraps this nested layout (app/store/layout.tsx), which wraps every page below it. Rebuild and the route table is unchanged in shape from Part 2 — adding a layout never adds, removes, or renames a route:

$ npm run build
...
Route (app)
┌ ○ /
├ ○ /_not-found
├ ○ /store
├ ○ /store/about
├ ○ /store/contact
├   /store/go/[id]
│ ├ ◐ /store/go/[id]
│ ├ ○ /store/go/p1
│ ├ ○ /store/go/p2
│ └ ○ /store/go/p3
├ ○ /store/products
├   /store/products/[id]
│ ├ ◐ /store/products/[id]
│ ├ ○ /store/products/p1
│ ├ ○ /store/products/p2
│ └ ○ /store/products/p3
└   /store/search/[...terms]
  ├ ◐ /store/search/[...terms]
  ├ ○ /store/search/silk
  └ ○ /store/search/pottery

(/store/go/[id] is section 6's addition, not a layout artifact — it is covered later in this part.)

Full file: examples/01-store-root-layout.tsx.

Done here? The practice set for Part 3 — including the solutions — is on the part page.

Search the guide