Skip to main content

Migrating Pages Router to App Router

Concept mapping​

Pages RouterApp Router direction
_appRoot and nested layouts plus focused providers
_documentRoot layout and Metadata APIs
getServerSidePropsAsync Server Component with request-time data
getStaticPropsPrerendered Server Component and explicit caching
getStaticPathsgenerateStaticParams
API RouteRoute Handler
next/headMetadata API
Page-level loadingloading.tsx and Suspense
Page-level errorerror.tsx / global-error.tsx

Migrate by route slice​

Move one route and its layouts, data access, mutations, tests, and telemetry together. Avoid creating a permanent half-migrated layer that fetches App Router data through legacy internal HTTP endpoints.

Data ownership​

Replace page-level props with direct server data access. Pass minimal serializable props into Client Components. Re-evaluate caching instead of copying old revalidate values mechanically.

Mutations​

Choose Server Functions for application-owned form mutations and Route Handlers for HTTP contracts, webhooks, external clients, or streaming APIs. Re-check authorization inside either boundary.

Shared providers​

Move providers as low as possible. A Client Component provider can be rendered by a Server Component layout without making the entire layout client-side.

Verification​

Compare rendered HTML, status codes, redirects, cookies, canonical URLs, metadata, analytics, accessibility, authorization, cache behavior, and production latency. Keep a redirect or rollback route until traffic confirms parity.