Skip to article content
LESSON 27 / 28

Pages Router and version migration

Read older interview questions accurately and translate their intent without mixing incompatible router APIs.

What you will be able to do

  • Explain Pages Router data-loading and routing APIs.
  • Map behavior to App Router boundaries rather than rename files blindly.
  • Identify Next.js 14, 15 and 16 assumptions.
  • Plan a route-by-route migration with preserved user behavior.

Ask which router and version the question assumes

An interview snippet using getServerSideProps is about the Pages Router. A snippet using an async page component and next/navigation is about the App Router. Both can describe server-rendered HTML, but their APIs and composition models differ. Begin by identifying the router and version before calling an example correct or obsolete.

Pages Router questions remain useful because many applications still contain those routes. Understand getStaticProps, getStaticPaths, getServerSideProps, pages/api, next/router, _app and _document as a coherent system. Do not insert getServerSideProps into app/page.tsx and expect it to become an App Router data loader.

Translate the purpose of the old API

getServerSideProps supplies request-time props for a Pages page; an App Router Server Component can perform its read directly. getStaticProps and getStaticPaths describe build-time generation and dynamic path selection; App Router uses its rendering/cache model and generateStaticParams. The mapping is conceptual, not a one-to-one textual replacement for every edge case.

The comparison below is a teaching excerpt for two separate projects or routes. It deliberately uses the previous App Router cache model with an explicit no-store read. When migrating to Cache Components, replace that assumption with the current cache and Suspense design instead of combining conflicting route controls.

Server execution

pages/catalog.tsx
export async function getServerSideProps() {
  const response = await fetch("https://example.test/catalog");
  if (!response.ok) throw new Error("Catalogue unavailable");
  return { props: { products: await response.json() } };
}
export default function Catalog({ products }: { products: { id: string; name: string }[] }) {
  return <ul>{products.map(product => <li key={product.id}>{product.name}</li>)}</ul>;
}

Server execution

app/catalog/page.tsx
export default async function Catalog() {
  const response = await fetch("https://example.test/catalog", { cache: "no-store" });
  if (!response.ok) throw new Error("Catalogue unavailable");
  const products: { id: string; name: string }[] = await response.json();
  return <ul>{products.map(product => <li key={product.id}>{product.name}</li>)}</ul>;
}

PAUSE AND PREDICT

An app/catalog/page.tsx exports getServerSideProps. Which response is accurate?

Choose one answer, then check your reasoning.

This check does not mark the lesson as solved.

Treat cache defaults as versioned facts

Older questions often assume cached fetches or GET handlers by default. Later versions changed defaults, and current Cache Components introduces a different explicit model. Mark those questions with their assumed version and answer both the historical behavior and the course baseline when useful. A confident answer that silently switches models is harder to trust than a precise qualified one.

Next.js 15 introduced asynchronous request APIs with temporary compatibility, and Next.js 16 removes synchronous access for the documented request APIs. Middleware terminology moves to Proxy. The current course references documentation showing 16.4.6, while the actual executable lab version must be read from its package and verification record. Documentation review is not proof of a successful runtime upgrade.

Keep the user contract stable while changing internals

Migrate a bounded route and its dependencies first. Preserve URL behavior, query parameters, authentication, metadata, error outcomes and browser history. Move interactive state into an intentional client component and keep server reads on the server. Providers belong at the narrowest useful boundary so a migration does not accidentally ship the entire application to the browser.

Layouts, persistent state and navigation differ enough to deserve dedicated checks. Test direct loads, client transitions, refresh and back navigation. Route conflicts must be resolved explicitly when both directories exist. Keep a rollback path for the migrated route and do not delete the old implementation until the replacement has demonstrated the intended behavior.

PAUSE AND PREDICT

An old interview answer says every fetch is cached automatically. How should a current answer respond?

Choose one answer, then check your reasoning.

This check does not mark the lesson as solved.

Explain the transition with a concrete example

Choose a product page that originally used getServerSideProps to load a product and a client-side cart widget. Describe the new async Server Component lookup, serialized product DTO, small interactive cart boundary, metadata and cache policy. Then explain what stayed the same for the user and which tests would detect a regression.

The exercise below classifies old API names with a small explicit lookup. It is not a codemod and does not prove a migration is complete. Use it as a recall aid, then perform a real migration by hand. The important skill is explaining execution, state and data freshness before and after the change.

Misconceptions to replace

Compare the tempting shortcut with the model you can verify in code.

CLAIM TO CHALLENGEMigrating to App Router is just renaming getStaticPaths.
A more accurate model

Translate unknown-path, prerendering and freshness behavior with the target model.

How to check it

Compare getStaticPaths intent with generateStaticParams and the real route checks.

CLAIM TO CHALLENGEAn old question is useless because it uses Pages Router.
A more accurate model

Understand its coherent model, label its version and explain the modern alternative.

How to check it

The migration lesson deliberately compares separate Pages and App examples.

Mistakes to catch in your own code

  • Mixing next/router and next/navigation assumptions.
  • Using getServerSideProps inside the app directory.
  • Copying old cache defaults into a current answer without a version label.
  • Treating a codemod as proof of semantic and UI parity.

Write it by hand

JavaScript logic playground

Classify legacy API migration intent

Implement solve(input). This sandbox runs the lesson's logic with FrontendX's isolated code runner. Next.js server behavior is verified in the project lab below.

  1. Input is an array of API name strings.
  2. Return one object per input with {api,target}. Use the documented lookup in the solution; unknown APIs map to review manually.
  3. This is a conceptual mapping exercise, not an automated source-code migration.

Tab moves to the next control. Use spaces to indent and return your answer from solve. Console output is not retained.

Ready when you are. Try the exercise before opening the worked solution.
Inspect 3 test cases
  1. Map server loading

    Input

    [
      "getServerSideProps",
      "getStaticProps"
    ]

    Expected

    [
      {
        "api": "getServerSideProps",
        "target": "request-time Server Component read"
      },
      {
        "api": "getStaticProps",
        "target": "explicit prerender and cache policy"
      }
    ]
  2. Map route primitives

    Input

    [
      "getStaticPaths",
      "pages/api"
    ]

    Expected

    [
      {
        "api": "getStaticPaths",
        "target": "generateStaticParams and unknown-path policy"
      },
      {
        "api": "pages/api",
        "target": "app Route Handler"
      }
    ]
  3. Keep unknown cases visible

    Input

    [
      "customPlugin"
    ]

    Expected

    [
      {
        "api": "customPlugin",
        "target": "review manually"
      }
    ]
Reveal the worked solution and reasoning
solution.js
function solve(input) {
  const targets = {
    getServerSideProps: "request-time Server Component read",
    getStaticProps: "explicit prerender and cache policy",
    getStaticPaths: "generateStaticParams and unknown-path policy",
    "next/router": "next/navigation with behavior review",
    "pages/api": "app Route Handler",
    "middleware.ts": "proxy.ts with runtime review"
  };
  return input.map(api => ({ api, target: Object.prototype.hasOwnProperty.call(targets, api) ? targets[api] : "review manually" }));
}

The mapping names the intended behavior rather than promising a mechanical one-line conversion.

Unknown APIs remain explicit review work.

After classification, migrate a real route and verify its user-facing contract.

Verify it in a real Next.js application

Next.js application lab

Build a legacy comparison beside the App Router example

Open the local application route /catalog after starting the workbench. Follow the experiment and collect the evidence described below.

Make the change

  1. Inspect the shipped /catalog and /catalog/keyboard routes, their async request props, cached catalogue helper and small client cart boundary. The provided project contains App Router routes; it does not include a Pages Router example.
  2. Implementation extension: create a separate Pages Router practice project with a legacy catalogue page and a real local data adapter. Give its version and caching assumptions explicitly; the example.test URL in the lesson is only an illustrative placeholder.
  3. Translate that page into a separate App Router comparison using the lab Cache Components model. Avoid assigning the same URL to both pages/ and app/ during a coexistence experiment.
  4. Compare direct loads, URL filters, refreshes, metadata, missing-product behavior and mutation freshness before retiring the legacy implementation. Trace which code and data move across the client boundary.
  5. Document how getServerSideProps or getStaticProps responsibilities become server reads, cache policy and request-time boundaries instead of copying their exports into an App Router page.

Check the behavior

  • The existing lab remains a working App Router baseline while the legacy fixture is implemented separately.
  • The migrated App Router page does not export getServerSideProps/getStaticProps, and awaits the request parameters used by its chosen version.
  • The comparison states the router, package version and cache configuration for each implementation.
  • Routing, data freshness, metadata and error behavior satisfy the written parity checks before the legacy fixture is removed.
Review the application reasoning

This lesson supplies the migration contract and contextual snippets. A Pages Router fixture, coexistence experiment and migration verification are assignments to build, not pre-existing routes in the downloaded application.

Open the project files and run instructions

A complete App Router application with catalogue routing, cart state, a task dashboard, practice sessions, tenant checks, cached data, hydration repairs, and HTTP streaming. Next.js 16.4.6 and React 19.3.0 are pinned in the project.

The playground opens a new editable copy. A local Node.js 22.14+ installation also runs the project. Use the local production build when measuring caching, streaming, or deployment behavior.

Terminal
cd nextjs-interview-lab
npm ci
npm run dev

# In a second terminal
npm test

# Stop dev, then verify the production application
npm run build
npm start

# In a second terminal, install the test browser once
npx playwright install chromium
npm run test:e2e

Open http://localhost:3003. The project includes a credential-free practice account selector and a single-process file store. Those choices make experiments reproducible; the security and deployment lessons show what a production system needs.

Explain it in an interview

Give your answer aloud before opening the explanation. Then answer the follow-ups using your implementation as evidence.

  1. 01What replaces getServerSideProps in App Router?

    An App Router Server Component can perform request-dependent server reads directly, with the appropriate current rendering and cache policy. It does not export getServerSideProps.

    I translate the intended behavior, including authentication, error outcomes and freshness. If Cache Components is enabled, I design runtime reads and Suspense explicitly rather than copying previous route controls.

    Follow-up questions

    • What happens to the interactive widget?
    • How would the metadata read the same product?
  2. 02How does getStaticPaths relate to generateStaticParams?

    Both participate in selecting dynamic route values for generation, but they belong to different router APIs and must be understood with their surrounding rendering model.

    I would inspect fallback behavior, unknown paths and revalidation requirements before migrating. Renaming the function alone does not establish the same runtime behavior.

    Follow-up questions

    • How should an unknown product route behave?
    • What would you verify after deployment?
  3. 03Why does an old params.slug snippet fail on the course baseline?

    The current documented request parameter contract is asynchronous. The server component should await params, and the code must be typed for that contract.

    I would also check whether the example was written for Next.js 14, the transitional Next.js 15 behavior or Next.js 16. Version context explains the discrepancy instead of treating every old example as careless.

    Follow-up questions

    • What other request APIs became asynchronous?
    • How can a client component consume a promised value?
  4. 04What would you test after moving one route to App Router?

    I would verify direct loading, client navigation, refresh, back history, query state, metadata, authorization and mutation freshness. I would also inspect the client bundle boundary and failure states.

    These checks protect the user contract. A successful compile proves that imports and types fit, not that persistent state or data access behaves as before.

    Follow-up questions

    • Which layout state should persist?
    • What is the rollback unit?

Check your understanding

Answer these without reopening the worked examples. The feedback explains the reasoning and the misconception behind each choice.

FINAL KNOWLEDGE CHECK

A codemod completes and TypeScript passes. What still needs verification?

Choose one answer, then check your reasoning.

This check does not mark the lesson as solved.

Your checkpoint

Mark what you can do independently

Loading your local progress.

Sources and further reading

© 2026 FrontendX. All rights reserved.