Skip to content

Chapter 1 of 8

Foundations of Next.js and the App Router

Next.js is a React framework created by Vercel that provides a complete toolkit for building production-ready web applications. It bundles together features that React alone does not offer out of the box, including server-side rendering, static site generation, file-based routing, and API routes. Since version 13, the recommended way to build Next.js applications is through the App Router, which uses an app/ directory and replaces the older Pages Router that relied on pages/. The App Router enables React Server Components, nested layouts, streaming, and the ability to colocate related files such as components, styles, and tests alongside the routes that use them.

The App Router uses the file system as the source of truth for routing. A route is created whenever a folder inside app/ contains a file named page.tsx. For instance, creating app/about/page.tsx exposes the path /about to visitors. This convention removes the need for an explicit routing configuration file and keeps the URL structure visually aligned with the project structure. As you build more complex applications, you can add dynamic segments, layouts, loading states, and error boundaries simply by placing the appropriate special files next to page.tsx in any folder.

To support this file-based approach, Next.js relies on several special filenames that each carry a specific role. Beyond page.tsx, files like layout.tsx, loading.tsx, error.tsx, and not-found.tsx give developers fine-grained control over the user experience at every route segment. Together, these files and the folder structure form a coherent system that lets you build everything from a simple marketing site to a complex dashboard without ever leaving the framework.

All chapters
  1. 1Foundations of Next.js and the App Router
  2. 2Server and Client Components
  3. 3Rendering Strategies
  4. 4Advanced Routing Patterns
  5. 5Layouts, Templates, and Special Files
  6. 6Data Fetching, Mutations, and Middleware
  7. 7Navigation Hooks and Components
  8. 8Configuration, Metadata, and Optimization

Drill it

Reading is not remembering. These come from the Nextjs Framework deck:

Q

What is Next.js?

Next.js is a React framework created by Vercel that provides features like server-side rendering, static site generation, file-based routing, and API routes out...

Q

What is the App Router in Next.js?

The App Router (introduced in Next.js 13) uses the app/ directory and supports React Server Components, nested layouts, streaming, and colocation of files. It r...

Q

How does file-based routing work in the App Router?

Routes are defined by the folder structure inside app/. A route is created by adding a page.tsx file inside a folder. For example, app/about/page.tsx maps to th...

Q

What is a Server Component in Next.js?

A Server Component renders on the server and sends HTML to the client. It is the default in the App Router. Server Components can directly access databases, rea...