Advertisement
Beginner Next.js, Custom App & Document in Pages Router

What is the purpose of the custom App component in the Pages Router?

Short answer

The custom App component, defined in pages/_app.js, wraps every page in your application, making it the perfect place to add global styles, shared layouts, or context providers that need to be available across the entire site.

Save Next.js mock interview
Advertisement
AModel answer
The custom App component, defined in pages/_app.js, wraps every page in your application, making it the perfect place to add global styles, shared layouts, or context providers that need to be available across the entire site.
// pages/_app.js
import '../styles/globals.css';

export default function MyApp({ Component, pageProps }) {
  return <Component {...pageProps} />;
}
Real-world example
A website imports its global CSS file once inside _app.js, ensuring consistent styling like fonts and colors are applied across every single page in the application.
Likely follow-ups
  • Can you add a global navigation bar inside the custom App component?
  • Does the custom App component exist in the App Router as well?
Related topics