Skip to the page

App Router foundations · core

File-system routing and special files

In the App Router each folder under app/ is a route segment, page.tsx makes it reachable, layout.tsx wraps it and stays mounted across navigation, and special files (loading, error, not-found, route) add Suspense, error and API behaviour per segment.

The notes

What you must know

  • Only page.tsx (UI) and route.ts (Route Handler) make a segment public; other files can be colocated safely. A route.ts cannot sit in the same segment as a page.tsx.
  • layout.tsx wraps its segment and children and does not re-render or lose state on navigation between its child pages (partial rendering). The root layout is required and must render <html> and <body>; it replaces _app and _document.
  • template.tsx is like a layout but remounts on every navigation (useful for enter animations or per-page effects).
  • loading.tsx wraps the page in a Suspense boundary; error.tsx wraps it in an error boundary (client component); not-found.tsx renders for notFound().
  • Dynamic segments: [id], catch-all [...slug] (one or more), optional catch-all [[...slug]] (zero or more). Route groups (marketing) organise without changing the URL; _private folders are never routes.
  • params and searchParams are Promises: const { id } = await params. Sync access was deprecated in 15 and removed in 16. Typed helpers: PageProps<"/blog/[slug]">, LayoutProps<...>, RouteContext<...>.
  • Next.js 16.3 root params: import { lang } from "next/root-params" reads params above the root layout (like [lang]) from any Server Component without prop drilling.
  • Layouts and pages are Server Components by default.

The red pen

Common traps: mistake → fix

  • Mistake: "Every file in app/ becomes a route"

    Fix: only page and route files are public.

  • Mistake: "Layouts re-render on every navigation, so they are a good place for auth checks"

    Fix: they persist; do auth close to the data.

  • Mistake: "params.id works directly"

    Fix: in Next 15+ params is a Promise; in 16 sync access is removed.

Easy to hard

Questions interviewers ask, easy to hard

  1. How does routing work in the App Router?
  2. What is the difference between layout.tsx and template.tsx?
  3. What do [slug], [...slug], [[...slug]] and (group) mean?
  4. Why are params and searchParams promises now?
  5. Design the route tree for a store with marketing pages, a shop and a signed-in account area.

Practise

Practise with these questions

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview