Skip to the solution
MediumFrontend5 min read

What is the difference between the App Router and the Pages Router?

826 views

The problem

Question presented to candidate: "Next.js has two routers. What is the difference, which one would you choose for a new project, and can they coexist?"

What a strong answer should cover:

  • Pages Router (pages/): every file is a route, data via getServerSideProps and getStaticProps, all components are client components that also ship to the browser.
  • App Router (app/): folders are routes and only page files are public; React Server Components by default; nested layouts, loading and error files, streaming, Server Actions.
  • The App Router is the recommended choice for new projects; the Pages Router is still supported.
  • Both can live in one project, which allows incremental migration; navigation between them is a full page load.
  • Pages Router props are serialized into __NEXT_DATA__; the App Router sends an RSC payload of rendered output.

Clarifying questions expected:

  • "New project or existing app?" β€” new projects use the App Router.
  • "Which libraries depend on next/router or _app?" β€” they influence the migration order.

Code / implementation expected: Yes β€” the same page in both routers.

  • nextjs
  • app-router
  • pages-router
  • routing

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

5 min read Β· 8 sections

Read the code

The same product page in both routers
// pages/products/[id].tsx  (Pages Router)
export async function getServerSideProps({ params }: { params: { id: string } }) {
  return { props: { product: await getProduct(params.id) } };
}
export default function Product({ product }: { product: { name: string } }) {
  return <h1>{product.name}</h1>;
}

// app/products/[id]/page.tsx  (App Router)
export default async function Product({ params }: { params: Promise<{ id: string }> }) {
  const product = await getProduct((await params).id);
  return <h1>{product.name}</h1>;
}

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 47 of 129 in Next.js

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

All Next.js questions
Up nextMedium

How do you handle redirects and rewrites in Next.js?

Continue