The App Router and the Pages Router
Next.js has two routers that can coexist. How the Pages Router worked, what the App Router changed, and why new projects should start with the App Router.
The App Router and the Pages Router
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- The Pages Router (the `pages` folder) treats every file as a route and fetches data with functions like `getServerSideProps`; the App Router (the `app` folder) uses folders, layouts, Server Components and async components.
- Both routers can live in one project, which is what makes incremental migration possible, but the same URL cannot be claimed by both: the build fails with an error naming the conflicting path.
- New projects should use the App Router. The Pages Router is still supported, which matters because a lot of production code is written in it.
- Most Pages Router concepts have an App Router counterpart: `_app` and `_document` become the root layout, `getServerSideProps` becomes an async Server Component, and `next/head` becomes the metadata API.
Why there are two
Next.js existed for years before React had Server Components. Its original router, now called the Pages Router, was built for the React of that time. When React gained Server Components and Suspense streaming, those features needed a router designed around them, and bolting them onto the old one was not possible. So Next.js 13 introduced a second router in a new folder, app, and kept the old one working.
That history explains the shape of the situation. Neither router is deprecated, the docs for the Pages Router still ship in the next package, and both can live in one repository. But the project scaffolder asks “Would you like to use App Router? (recommended)”, and everything new in the framework lands there first.
The Pages Router in one minute
In pages/, every file is a route: pages/about.tsx is /about, pages/blog/[slug].tsx is /blog/:slug. A page is a component with data loaded by a separate exported function:
// pages/posts/[id].tsx
export async function getServerSideProps({ params }) {
const post = await getPost(params.id);
return { props: { post } };
}
export default function Post({ post }) {
return <h1>{post.title}</h1>;
}
Shared wrappers live in special files, _app.tsx and _document.tsx. Every component is a regular React component that ships to the browser and hydrates there. There is no "use client" because there is no other kind.
What the App Router changed
In app/, folders are routes, and a page file makes one public. The same page is an async component:
// app/posts/[id]/page.tsx
export default async function Post({ params }: PageProps<"/posts/[id]">) {
const { id } = await params;
const post = await getPost(id);
return <h1>{post.title}</h1>;
}
The big shifts:
- Server Components by default. Components run on the server and do not ship their code. Interactivity is opt-in per file, which is the subject of the use client boundary.
- Nested layouts. A
layoutwraps its segment and everything below, and keeps its state across navigation. The Pages Router had one global_app. - Streaming.
loadingfiles and<Suspense>let parts of a page arrive as they are ready (loading UI and streaming). - Data where you need it. No separate data function; you fetch inside the component that uses the data.
Rough translations: _app and _document become the root layout; getServerSideProps and getStaticProps become awaited calls inside a Server Component; next/head becomes the metadata export; pages/api becomes route files.
Using both at once
The two folders coexist. This is the supported way to migrate: leave old routes in pages/, build new ones in app/, and move routes over as it makes sense. The rule is that one URL belongs to exactly one router. I checked this on a scratch project: with pages/about.tsx and app/(marketing)/about/page.tsx both present, next build fails with “App Router and Pages Router both match path: /about”. With non-colliding routes, the build lists them under two separate tables, Route (app) and Route (pages).
If you are starting fresh, use app. If you are joining a project that uses pages, you will read and write both; the last lesson in this roadmap covers maintaining it.
What the video covers
Lee Robinson’s video, made when Next.js 13.4 stabilized the App Router, shows how to move routes from pages/ to app/. Its chapters cover static routes, Server and Client Components, mixing them, the metadata API replacing next/head, replacing getServerSideProps with async components, passing data to Client Components, fetching and caching, and layouts versus _app and _document. That makes it a good tour of both routers side by side, which is the point of this lesson.
It dates from 2023, so its caching details are out of date for Next.js 16 and you should read the data-fetching group of this roadmap for those. The router comparison itself still holds.
Where this fits
You now know what the app folder is for and why it is not the only option. Next, Turbopack and the dev server covers what runs when you start the project.
Check yourself
What happens if `pages/about.tsx` and `app/about/page.tsx` both exist?
The build fails. Next.js does not allow both routers to match the same path, and the error tells you to remove one of the conflicting routes.
Where do you fetch data in the App Router, compared with the Pages Router?
In the Pages Router you export a function such as `getServerSideProps` or `getStaticProps` that runs before the page and passes props in. In the App Router the page is an async Server Component, so you await your data inside it.
Why does a project with both `pages` and `app` exist at all?
It lets a team migrate one route at a time instead of rewriting everything at once. Routes that do not collide can live in either folder while the app keeps working.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.