Before you create your first project, it helps to see the big picture of how Next.js is built. Think of a restaurant again. The customer sits in the dining room (the browser). The kitchen (the server) cooks the dishes. A waiter (Next.js) takes orders to the kitchen and brings the plates back. In this lesson we look at who does what, and we meet the two systems that Next.js has used to organise pages.
The three parts of a Next.js app
- The build step. When you run the build command, Next.js reads your files, compiles your code with a fast tool called Turbopack, and prepares what it can ahead of time.
- The server. When someone visits, a Node.js server (or a platform that behaves like one) answers. It sends the prepared pages and builds the parts that need fresh data.
- The browser. It shows the HTML, loads a small amount of JavaScript and makes the interactive parts work. React in the browser takes over buttons, forms and anything with state.
This split is the main idea of the modern App Router: do as much work as possible on the server, where data and secrets are safe, and send only what the browser really needs.
Two routers, two eras
A router decides which file answers which URL. Next.js has two.
The Pages Router (older)
The Pages Router uses a folder called pages. Every file in it becomes a page. To load data you write special functions such as getServerSideProps or getStaticProps. It is stable and many large sites still use it, so you may meet it at work.
The App Router (modern)
The App Router uses a folder called app. Every folder becomes part of the URL, and a file called page defines what shows there. It adds layouts that stay on screen while you move between pages, loading and error screens, and React Server Components. It is the recommended choice for new projects and it is what create-next-app gives you today.
Differences at a glance
- Folder: pages for the Pages Router, app for the App Router.
- Page file: any file in pages, but a file named page in the App Router.
- Components: in the Pages Router every component runs in the browser too. In the App Router components are Server Components unless you mark them otherwise.
- Data loading: special functions in the Pages Router, plain async components in the App Router.
- Layouts: one shared wrapper file in the Pages Router, and nested layouts for every folder in the App Router.
- Special screens: the App Router has loading, error and not-found files for each route.
Which should you learn?
Learn the App Router. It is where the framework is going, new features arrive there first and it gives the best results for search and speed. Spend a little time later reading about the Pages Router, so you can understand an older codebase. Almost everything about React itself stays the same in both.
What else is inside a Next.js app?
- Route Handlers: server endpoints that return JSON or other responses.
- Server Actions: functions that run on the server when a form is sent.
- A request step: in Next.js 16 the file that used to be called middleware is now called proxy. It runs before a request reaches a page, for example to redirect a visitor.
- Configuration: a file called next.config.ts for settings.
- The public folder: files such as images that are served as they are.
Your task
- Draw the three parts (build, server, browser) and write one sentence about what each does.
- Write down two reasons the App Router is better for a new project and one reason an old project might still use the Pages Router.
- Search for a tutorial that uses getServerSideProps. Decide which router it uses.
How to check it worked
- You can say which folder each router uses.
- You can describe the three parts of a Next.js app.
- You know why this course teaches the App Router.