Q32: What were _app.js and _document.js in the legacy Pages Router?

In the legacy Pages Router:

  • _app.js: Wrapped all page components. Used for global CSS imports, context providers, and layout persistence.
  • _document.js: Custom superset of HTML document tags (<html>, <head>, <body>). Executed strictly on the server to inject custom scripts or SSR style tags.
Pages Router Custom _app.js
// pages/_app.js (Pages Router Legacy)
import '../styles/globals.css';

export default function MyApp({ Component, pageProps }) {
  return (
    <ThemeProvider>
      <Component {...pageProps} />
    </ThemeProvider>
  );
}
💡 _app.js initialized global styles and providers across all Pages Router routes.
Key Takeaways
  • _app.js handled component wrappers, global styles, and providers.
  • _document.js customized raw HTML document structures on the server.
Knowledge Check

Which App Router file replaces both legacy _app.js and _document.js files?