Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
The App Router  ›  Lesson

Pages Router and App Router

Pages 12 minNext.js has two routers: the older Pages Router built on the pages folder and special data functions, and the App Router built on the app folder and React Server Components.

Pages Router and App Router

Search for a Next.js answer and half the results use getServerSideProps and a pages folder, while the other half use async components in an app folder. Both are correct, for different routers. Next.js has shipped two routing systems, and you need to recognise which one a piece of code belongs to.

The rule

pages is the older router; app is the current one. Check the folder first.

The Pages Router (the original, still supported) lives in a pages folder. Each file is a route, and data is loaded by special exported functions that run on the server and pass props to the page.

// pages/trails/[slug].tsx  →  /trails/misty-ridge
export async function getStaticProps({ params }) {
  return { props: { trail: await getTrail(params.slug) } };
}
export default function Trail({ trail }) {
  return <h1>{trail.name}</h1>;
}

Other Pages Router markers: getServerSideProps (render per request), getStaticPaths, _app.tsx and _document.tsx for the shared shell, API endpoints in pages/api, and useRouter from next/router.

The App Router (introduced in Next.js 13, and the recommended choice for new work) lives in an app folder. Each folder is a segment and a page.tsx makes it public. Components are React Server Components by default, so a page can load its own data.

// app/trails/[slug]/page.tsx  →  /trails/misty-ridge
export default async function Trail({ params }) {
  const { slug } = await params;
  const trail = await getTrail(slug);
  return <h1>{trail.name}</h1>;
}

App Router markers: page.tsx, layout.tsx, loading.tsx, route.ts, "use client", and useRouter from next/navigation.

Both folders can exist in one project, which lets teams migrate one route at a time. The same URL must not be defined in both.

The shortcut

Before using any snippet, look for a fingerprint: a get…Props function or a pages/ path means Pages Router; an async page, page.tsx or "use client" means App Router. Do not mix a snippet from one into the other.

Which router is this snippet for?Step 1 of 4
  1. Look at the path

    pages/about.tsx: a file named after the route. Pages Router.

The trap is pasting getServerSideProps into app/…/page.tsx. The App Router does not support it, so instead of loading your data you get an error. Rewrite the loading as an await inside the page.

Drills

Answer fast — trust the rule.

quick drill

Which file serves /about in the Pages Router?

quick drill

Which function belongs only to the Pages Router?

quick drill

Can a project use both pages and app at the same time?

quick drill

How does an App Router page load its data?

Remember

  • pages is the older router (files as routes, get…Props); app is the current one (folders, async server components).
  • Shortcut: check the fingerprint before using a snippet.
  • Trap: Pages Router data functions are not supported inside the App Router.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainReading someone else's project

You join a team whose Next.js project has both a pages folder and an app folder. Explain how you tell which router serves a URL, how each router makes an About page and loads data for it, and why both might exist at once.