Next.js Developer interview question · Most asked

What are the differences between the App Router and the Pages Router?

Summary

The App Router (app/ directory, stable since Next.js 13.4) is built on React Server Components with nested layouts, streaming, Server Actions and colocated loading/error UI. The Pages Router (pages/) uses getServerSideProps/getStaticProps and client-rendered page components.

Longer Answer

Both can coexist during migration. App Router concepts: layout.tsx (persistent shared UI), page.tsx (route UI), loading.tsx (Suspense fallback), error.tsx (error boundary), route.ts (API handlers), and async Server Components that fetch data directly. Navigation hooks come from next/navigation instead of next/router. New projects should use the App Router.

Key Points

  • App Router: RSC, nested layouts, streaming, Server Actions
  • Pages Router: getServerSideProps/getStaticProps
  • Can coexist for incremental migration
  • Different router hooks (next/navigation vs next/router)

Comparison / Tradeoffs

Concept Pages Router App Router
Data fetching getServerSideProps / getStaticProps async Server Components, fetch, caching APIs
Layouts _app.tsx, manual Nested layout.tsx
API pages/api/* route.ts Route Handlers
Mutations API routes Server Actions

More most-asked Next.js Developer questions

← All Next.js Developer questions