Q46: How do you migrate a Pages Router component with getServerSideProps to the App Router?

In the App Router, delete getServerSideProps. Convert the page component into an async Server Component, and call dynamic fetch('...', { cache: 'no-store' }) or query databases directly inside the component body.

Migration Example
// BEFORE (pages/user.js)
export async function getServerSideProps() {
  const user = await fetchUser();
  return { props: { user } };
}
export default function Page({ user }) { return <h1>{user.name}</h1>; }

// AFTER (app/user/page.js)
export default async function Page() {
  const user = await fetchUser(); // Direct execution in Server Component!
  return <h1>{user.name}</h1>;
}

App Router eliminates getServerSideProps wrapper code in favor of async Server Components.

Key Takeaways
  • Replace getServerSideProps with direct async calls inside React Server Components.

  • Use { cache: 'no-store' } or dynamic functions (cookies(), headers()) to force request-time rendering.

Knowledge Check

What replaces getServerSideProps when migrating a page to an App Router Server Component?