Skip to article content
FrontendXLesson 01 / 20

The App Router Mental Model

A version-qualified path through the Next.js App Router: server components, client boundaries, data fetching, caching layers, streaming, error handling, proxy, images, performance, testing and deployment, with the Next.js 15 and 16 behavior changes called out where they matter.

beginner · about 40 minutes · 6 exercises

  • Predict
  • Explain
  • Implement
  • Debug
  • Test
  • Interview

What you will be able to do

#
  • Name the App Router file conventions and state which file renders at a given URL.
  • Explain why the App Router is server-first and what that changes for data and secrets.
  • State the version-qualified differences between Next.js 14, 15 and 16 that affect daily work.

Overview

#

Routes are a file tree

In the App Router the app directory is the route tree. A folder becomes a URL segment and a special file inside it becomes what that segment renders. page.tsx renders the route, layout.tsx wraps child segments and persists across navigations, loading.tsx wraps the segment in a Suspense boundary, error.tsx catches render errors, not-found.tsx renders 404 UI, and route.ts exposes a server endpoint instead of UI. Only these special filenames create behavior; an ordinary utils.ts file in app/dashboard is just a module, not a route.

snippet.txt
app/
  layout.tsx        # required root layout, renders <html> and <body>
  page.tsx          # renders /
  dashboard/
    page.tsx        # renders /dashboard
    settings/
      page.tsx      # renders /dashboard/settings
    error.tsx       # error boundary for /dashboard and below

The App Router has been stable since Next.js 13.4. Versions matter in this course because behavior changed in ways interviews probe. Next.js 15 made the request APIs async: params, searchParams, cookies(), headers() and draftMode() return promises, and the synchronous access pattern was deprecated. Next.js 15 also stopped caching fetch calls by default. Next.js 16 finished the removal so request APIs can only be awaited, made Turbopack the default bundler for both next dev and next build, renamed the middleware convention to proxy, and introduced Cache Components behind the cacheComponents config flag, which new create-next-app projects enable by default.

Server-first by default

Every component you write in app is a React Server Component unless you opt out with 'use client'. Server components run only on the server: they can await data, read databases, keep secrets in environment variables and ship zero JavaScript for their own logic. Interactivity is the exception you add deliberately at a client boundary. This inversion, from client-first with server helpers to server-first with client islands, is the single biggest mental model change from the Pages Router.

What ships to the browser

A server component's output is a serialized React tree, not its source. The browser receives rendered UI plus a small runtime that can reconcile streamed updates. A client component ships its real JavaScript. This is why the default is a performance win and why careless 'use client' placement at a high level of the tree drags whole subtrees into the bundle.

Exercises

#

Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.

  1. Exercise 1Predict

    Given this app tree, which component renders when a user visits /dashboard/settings? app/layout.tsx app/page.tsx app/dashboard/page.tsx app/dashboard/settings/page.tsx app/dashboard/settings/loading.tsx

    Choose the best answer
  2. Exercise 2Explain

    Explain in your own words what server-first means in the App Router and one concrete benefit it gives you on day one.

    Reveal the reference answer
    reference.text
    Every component in app is a React Server Component until you mark a boundary with 'use client'. Server components execute on the server only, so they can await databases and APIs directly, read secret environment variables without exposing them, and contribute no component JavaScript to the client bundle. The benefit: a data-driven page needs no API route, no useEffect fetch and no client data library for the first render.

    Authored expected output: A definition of server-first plus at least one concrete benefit such as direct data access, secret safety or zero bundle cost.

    The default flipped from the Pages Router. Interactivity is opt-in at boundaries rather than the baseline.

  3. Exercise 3Implement

    Create the smallest valid root route for an App Router project: a root layout that renders html and body and a home page that exports a page title through the metadata API.

    starter.tsx
    # app/layout.tsx
    // TODO: export a default component rendering <html> and <body>
    
    # app/page.tsx
    // TODO: export metadata with title 'Home' and a default component rendering an h1

    Reveal the reference answer
    reference.tsx
    // app/layout.tsx
    export default function RootLayout({ children }: { children: React.ReactNode }) {
      return (
        <html lang="en">
          <body>{children}</body>
        </html>
      );
    }
    
    // app/page.tsx
    export const metadata = { title: "Home" };
    
    export default function Page() {
      return <h1>Home</h1>;
    }

    Authored expected output: A valid root layout plus a home page whose document title is Home.

    The root layout is the only file allowed to render html and body. Static metadata is a plain exported object; dynamic metadata uses generateMetadata.

  4. Exercise 4Debug

    This project has app/Dashboard/page.tsx but visiting /dashboard returns 404. Find the bug and fix it.

    starter.text
    app/
      Dashboard/
        Page.tsx   // exports default function Dashboard() { ... }

    Reveal the reference answer
    reference.text
    Two problems: the folder is named Dashboard with a capital D so it maps to /Dashboard, and the file is named Page.tsx instead of the reserved lowercase page.tsx. Rename the folder to dashboard and the file to page.tsx. Route segments are case-sensitive and only the exact reserved filename in lowercase is recognized.

    Authored expected output: /dashboard renders after renaming the folder to dashboard and the file to page.tsx.

    File conventions are exact lowercase names. Capitalized names are treated as ordinary files and do not create routes.

  5. Exercise 5Test

    Write a pure helper that turns a file path inside app into its URL path, treating page.tsx as the route file and dropping it, and write assertions for three cases: app/page.tsx maps to /, app/dashboard/settings/page.tsx maps to /dashboard/settings, and app/lib/util.ts maps to null because it is not a route file.

    starter.ts
    export function filePathToRoute(path: string): string | null {
      // TODO
    }
    
    // assertions
    // expect(filePathToRoute('app/page.tsx')).toBe('/')
    // expect(filePathToRoute('app/dashboard/settings/page.tsx')).toBe('/dashboard/settings')
    // expect(filePathToRoute('app/lib/util.ts')).toBe(null)

    Reveal the reference answer
    reference.ts
    export function filePathToRoute(path: string): string | null {
      const parts = path.split('/');
      const file = parts[parts.length - 1];
      if (file !== 'page.tsx' && file !== 'page.jsx') return null;
      const segments = parts.slice(1, -1).filter((s) => !s.startsWith('(') && !s.startsWith('@'));
      const route = '/' + segments.join('/');
      return route === '/' ? '/' : route;
    }
    
    // app/page.tsx has no segments, so the result is '/'.
    // Route groups in parentheses and parallel slots prefixed with @ do not appear in URLs, so they are filtered.

    Authored expected output: The three assertions pass: '/', '/dashboard/settings' and null.

    This mirrors how the App Router derives URLs: nested folders are segments, page.tsx is the leaf, and group or slot folders are URL-invisible.

  6. Exercise 6Interview

    An interviewer asks: how does the App Router change your mental model compared to the Pages Router? Give a structured answer covering rendering default, data fetching, and one version-qualified change.

    Reveal the reference answer
    reference.text
    Structure the answer in three beats. First, rendering: pages were client components by default and the whole tree hydrated; in the App Router everything is a server component until you opt into a client boundary, so data-heavy UI ships less JavaScript. Second, data: getStaticProps and getServerSideProps are gone; components await data directly next to the UI that uses it, and caching is expressed per fetch or per cached function instead of per page function. Third, a version-qualified change: since Next.js 15 the request APIs (params, searchParams, cookies, headers) are promises you await, and Next.js 16 removed synchronous access entirely, so code written against the old sync shape breaks on upgrade.

    Authored expected output: Three structured beats covering rendering default, colocated data fetching, and an async request API change.

    Interviewers reward a model-level answer over an API list. Naming the version where behavior changed signals production experience.

Common misconceptions

#
  • The App Router is a folder rename. It is a different rendering model: components are server components by default and layouts persist across child navigations.
  • Every file inside app becomes a route. Only the reserved filenames (page, layout, route, error, loading, not-found, template, default, global-error, global-not-found, proxy) create routes or behavior.
  • You cannot have app and pages at the same time. Both directories can coexist during an incremental migration; the pages router routes keep working alongside app routes.
  • Next.js version differences are cosmetic. Fetch caching defaults, async request APIs, the bundler and the middleware convention all changed between 14 and 16.

Follow-up practice

#
  • nextjs-routing-and-navigation
  • nextjs-server-components

Related resources

#

Your progress

#

Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.

Verification: authored. Answers and outputs on this page are authored reference material, not executed results.

© 2026 FrontendX. All rights reserved.