Next.js versions and the Pages Router

What changed from 14 to 16, and the router you'll still meet.

Builds on Rendering and deploying Next.js.

The last four chapters taught Next.js 16 as if every app started there. Most don't. You'll join codebases on 14 with implicit caching, on 15 halfway through the async request API migration, and on the Pages Router, which was Next.js's only router from its 2016 launch until 2023, still ships in Next.js 16, and still runs a large share of production Next.js. Interviewers ask about it because their apps use it, or because they want to know whether you understand what the App Router replaced and why.

This is a reference chapter: what changed in each major version, the Pages Router's data functions mapped to their App Router equivalents, and how to migrate.

The problem: "which Next.js is this?"#

Three snippets, all real Next.js, all fetching a book:

pages/books/[id].tsx (Pages Router)
export async function getServerSideProps({ params }) {
  return { props: { book: await getBook(params.id) } };
}
app/books/[id]/page.tsx (Next.js 14)
export default async function Page({ params }: { params: { id: string } }) {
  const book = await fetch(`https://api.example.com/books/${params.id}`).then((r) => r.json());
  // ...cached forever by default in 14, unless you opt out
}
app/books/[id]/page.tsx (Next.js 16)
export default async function Page({ params }: PageProps<"/books/[id]">) {
  const { id } = await params; // params is a Promise
  const book = await getBook(id); // uncached unless getBook says "use cache"
}

Same feature, three mental models. Reading a codebase well starts with knowing which one you're in.

What changed: 14, 15, 16#

Next.js 14 (Oct 2023)Next.js 15 (Oct 2024)Next.js 16 (Oct 2025) and 16.x
React1819 for the App Router; Pages Router supports 18 and 1919.2 features; 16.4 ships React 19.3
Minimum Node.js18.1718.1820.9
fetch cachingCached by defaultNot cached by defaultNot cached; opt in with "use cache" (Cache Components)
GET Route HandlersCached by defaultNot cached by defaultFollow the same prerendering model as pages under Cache Components
Client Router CacheReuses dynamic segments 30 s, static 5 minDoesn't reuse page segments by default (staleTimes.dynamic 0)Rewritten: per-segment prefetching, layout deduplication; stale time from cacheLife
params, searchParams, cookies(), headers()SynchronousAsync, with a temporary sync shim and warningsAsync only
Caching modelImplicit: four layersSame layers, cautious defaults; "use cache" experimentalCache Components (cacheComponents: true), default in new apps since 16.4
PPRPreviewExperimental (experimental.ppr)Flag removed; it's how Cache Components renders
Middlewaremiddleware.ts, Edge runtimeSame; Node.js runtime for middleware stable in 15.5proxy.ts on Node.js; middleware.ts deprecated
Bundlerwebpack; Turbopack dev in betaTurbopack stable for next devTurbopack default for dev and build
Server ActionsStableStable, with unguessable ids and dead-code eliminationPlus updateTag and refresh
React CompilerNot availableExperimental optionreactCompiler: true stable, off by default
Othernext.config.ts, <Form> from next/form, after() (stable in 15.1), instrumentation.ts stablenext lint removed, AMP removed, serverRuntimeConfig/publicRuntimeConfig removed, default.tsx required for parallel slots, next/image default changes

And the 16.x minor releases, which changed more than most majors:

  • Next.js 16.2 Adapters stable (deploy anywhere through a build adapter), transitionTypes on <Link>, next start --inspect, faster Server Components payload parsing.
  • Next.js 16.3 Instant Navigations: Partial Prefetching (partialPrefetching: true), Instant Insights in devtools, a Playwright instant() helper, App Shells for unlisted ISR params, catchError and retry for error boundaries, root params from next/root-params, disk-cached builds.
  • Next.js 16.4 React 19.3, Cache Components on by default in create-next-app (with Partial Prefetching now treated as part of the model), ensureStatic, navigation() and prefetch() from next/cache, next upgrade --agent. The 16.4 post says Cache Components becomes the default in Next.js 17.

The arc is worth being able to say in one breath: 14 cached everything implicitly and surprised people; 15 turned the implicit caching off; 16 replaced it with explicit, composable caching and made partial prerendering the rendering model.

The Pages Router#

Before the App Router (stable in 13.4, May 2023), every Next.js app used pages/. Each file is a route: pages/books/[id].tsx serves /books/42. Pages are ordinary React components rendered on the server and hydrated on the client, so every component is a Client Component in today's terms; there are no Server Components. Data comes from special functions exported next to the page, which run only on the server and pass props in.

getServerSideProps: render per request#

pages/books/[id].tsx
import type { GetServerSideProps, InferGetServerSidePropsType } from "next";

export const getServerSideProps = (async ({ params, req, query }) => {
  const book = await getBook(params!.id as string);
  if (!book) return { notFound: true };
  if (book.moved) return { redirect: { destination: `/books/${book.newId}`, permanent: true } };
  return { props: { book } };
}) satisfies GetServerSideProps;

export default function BookPage({ book }: InferGetServerSidePropsType<typeof getServerSideProps>) {
  return <h1>{book.title}</h1>;
}

Runs on every request, on the server, with access to the request (req, res, query, params, cookies through req). Returns props, notFound or redirect. On client-side navigations, Next.js calls it through a JSON endpoint and renders the page with the result. App Router equivalent: an async Server Component that reads uncached data or cookies(), inside Suspense.

getStaticProps and getStaticPaths: render at build time#

pages/books/[id].tsx
import type { GetStaticPaths, GetStaticProps } from "next";

export const getStaticPaths = (async () => {
  const popular = await getPopularBooks(200);
  return {
    paths: popular.map((b) => ({ params: { id: b.id } })),
    fallback: "blocking", // or false, or true
  };
}) satisfies GetStaticPaths;

export const getStaticProps = (async ({ params }) => {
  const book = await getBook(params!.id as string);
  if (!book) return { notFound: true };
  return { props: { book }, revalidate: 3600 }; // ISR: rebuild at most hourly
}) satisfies GetStaticProps;

getStaticProps runs at build time. getStaticPaths lists which dynamic paths to build, and fallback decides what happens for the rest:

  • false: any other path is a 404.
  • "blocking": the first request for an unlisted path waits for the server to render it (like SSR), then it's cached as static.
  • true: the first request gets a fallback version of the page immediately (router.isFallback is true and props are empty), the page renders in the background, then the browser swaps in the real props.

Returning revalidate: N turns on Incremental Static Regeneration, the feature Next.js introduced in 9.5: after N seconds, the next request still gets the cached page and triggers a background rebuild. For on-demand ISR, an API route calls res.revalidate("/books/42").

When Pages Router data functions run
next buildRequest 1Request 2Req. 3, 61 s laterRequest 4getStaticPropsno revalidate (SSG)runscached HTMLcached HTMLcached HTMLcached HTMLgetStaticPropsrevalidate: 60 (ISR)runscached HTMLcached HTMLstale + rerunfresh HTMLgetServerSidePropsSSRnot runrunsrunsrunsruns
getStaticProps runs at build time; with revalidate, the first request after the interval still gets the old page and triggers a rebuild in the background (the next request sees it). getServerSideProps runs on every request.

The mapping to the App Router:

Pages RouterApp Router, Next.js 16 with Cache Components
getServerSidePropsAsync Server Component reading uncached data or runtime APIs, inside Suspense
getStaticPropsAsync Server Component whose data completes at build time, or is in "use cache"
revalidate: 3600cacheLife("hours") (or a custom profile) in the "use cache" scope
res.revalidate(path)revalidatePath(path), or better, tags with updateTag / revalidateTag
getStaticPathsgenerateStaticParams
fallback: trueSince 16.3, unlisted params get the App Shell instantly and upgrade in the background
fallback: "blocking"ensureStatic = "navigation" makes the first request wait for the complete static result
fallback: falsenotFound() for unknown params (dynamicParams = false in the previous model)
notFound: true / redirectnotFound() / redirect() from next/navigation
pages/api/*app/**/route.ts Route Handlers, or Server Actions for your own forms
_app.tsxapp/layout.tsx (root layout)
_document.tsxThe <html> and <body> in the root layout
next/headmetadata / generateMetadata
useRouter from next/routeruseRouter, usePathname, useSearchParams from next/navigation
getInitialProps (legacy)Not supported in app/

API routes#

pages/api/books.ts
import type { NextApiRequest, NextApiResponse } from "next";

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
  if (req.method === "POST") {
    const book = await insertBook(req.body);
    return res.status(201).json(book);
  }
  res.status(200).json(await getBooks());
}

Node-style req and res, one default export handling every method. The App Router's Route Handlers use Web Request and Response with one export per method.

_app and _document#

pages/_app.tsx wraps every page: global CSS imports, providers, persistent layout. It receives Component and pageProps and must render <Component {...pageProps} />. pages/_document.tsx customizes the HTML shell, rendered only on the server, with Html, Head, Main and NextScript from next/document. There are no nested layouts in the Pages Router; per-page layouts are a pattern (a getLayout function on the page component) rather than a framework feature, and they don't keep server data separate per segment.

getInitialProps#

The oldest data API, from before 9.3. It runs on the server for the first load and in the browser on client navigations, so its code ships to the client and must work in both places. Using it in _app disables Automatic Static Optimization for every page. You'll see it in old codebases; the answer to "should we use it" is no.

Migration paths#

Pages to App Router. Both directories work in the same app, so migrate route by route. A URL can't be defined in both, so you move a page by deleting it from pages/ and creating it in app/. Usual order: create app/layout.tsx from _app and _document, move leaf pages first, turn getServerSideProps and getStaticProps into data fetched in Server Components, replace next/router with next/navigation, then move API routes that your own UI calls into Server Actions. Components that use hooks or browser APIs need "use client". Navigating between a Pages route and an App route is a full page load, not a soft navigation, so migrate sections that users move between together.

14 to 15. Run npx @next/codemod@canary upgrade latest; it includes the async request API codemod (next-async-request-api). Then audit caching. A route with no request-time APIs is still prerendered in 15, so its fetch runs once at build as before. The change bites on dynamic routes (anything reading cookies(), headers() or searchParams): in 14 their fetch calls were served from the Data Cache, and in 15 they hit the upstream on every request. GET Route Handlers are no longer cached either. That can raise load on your APIs a lot. Add cache: "force-cache" or next: { revalidate } deliberately. Upgrade React to 19 for the App Router.

15 to 16. The same upgrade codemod, plus: Node.js 20.9+, remove remaining synchronous request API access, rename middleware.ts to proxy.ts (codemod middleware-to-proxy), add the second argument to revalidateTag (or switch to updateTag in actions), add default.tsx to every parallel slot, replace next lint with ESLint or Biome directly, replace runtime config with environment variables, check custom webpack config against Turbopack, and drop unstable_ from cacheLife and cacheTag. Since 16.4, npx next@canary upgrade --agent=latest prepares version-specific guidance for a coding agent.

Previous model to Cache Components. A separate step, done on 16. Turn on cacheComponents and partialPrefetching, then work through the build errors: each one is a component reading uncached data outside Suspense. Wrap it in Suspense or move the data into "use cache" with an explicit cacheLife. Delete dynamic, revalidate, fetchCache, dynamicParams and runtime segment exports. Replace unstable_cache and fetch cache options with "use cache".

Pitfalls#

Check your understanding#

PredictThree fallbacks

pages/books/[id].tsx uses getStaticPaths returning only /books/1 and /books/2, and getStaticProps with revalidate: 60. A user visits /books/3, which exists in the database. What do they see with fallback: false, fallback: "blocking" and fallback: true? What does the second visitor to /books/3 see?

Quick checkTranslate to the App Router

A Pages Router page uses getStaticProps with revalidate: 3600. What's the closest equivalent in a Next.js 16 app with Cache Components?

Quick checkAfter the upgrade

After upgrading from Next.js 14 to 15 with no code changes, the API behind your product pages gets far more traffic. What's the most likely cause?

Explain it out loudPages to App Router

An interviewer asks: "We have a large Pages Router app on Next.js 13. How would you get it to the App Router on Next.js 16?"

Interview angle

Say it in 30 seconds

Next.js 14 cached aggressively and implicitly: fetch, static routes and GET handlers by default. Next.js 15 turned that off and made params, searchParams, cookies and headers async. Next.js 16 replaced implicit caching with Cache Components and "use cache", made partial prerendering the rendering model, renamed middleware to proxy.ts, and made Turbopack the default; 16.3 added Instant Navigations, and 16.4 turned Cache Components on for new apps. The Pages Router, still supported, fetches with getServerSideProps per request and getStaticProps with revalidate for ISR, and each maps to Server Components, cacheLife and generateStaticParams in the App Router.

What changed between Next.js 14, 15 and 16?

intermediate

In the Pages Router, what's the difference between getServerSideProps and getStaticProps?

basic

How do Pages Router concepts map onto the App Router?

intermediate

What's the biggest risk when upgrading a Next.js 14 App Router app to 15?

senior

Recap#

  • Next.js 14 cached fetch, routes and GET handlers by default; 15 made fetch, GET handlers and client page segments uncached by default and made request APIs async; 16 introduced Cache Components, proxy.ts, Turbopack by default, and async-only request APIs.
  • 16.2 stabilized adapters, 16.3 added Instant Navigations and Partial Prefetching, and 16.4 turned Cache Components on for new apps and added ensureStatic. The 16.4 post says Next.js 17 is planned to make Cache Components the default.
  • The Pages Router uses getServerSideProps (per request), getStaticProps with revalidate (build time plus ISR), getStaticPaths with fallback, API routes, _app and _document. Every component is a Client Component there.
  • Each maps to an App Router feature: Server Components with uncached or cached data, cacheLife, generateStaticParams, Route Handlers or Server Actions, and the root layout.
  • Migrate incrementally: upgrade the framework first, move routes from pages/ to app/ in sections, then adopt Cache Components and fix its build errors.

Sources#