Web Development

Next.js App Router vs Pages Router: Which is Better?

A developer's guide to choosing between the Next.js App Router and Pages Router for your next project.

By · · 5 min read

Short answer

The App Router is the modern standard for Next.js, offering React Server Components, streaming, and advanced layouts. Use it for all new projects to benefit from better performance and architecture. The Pages Router remains stable for legacy support, but it lacks the features that power modern Next.js performance.

Key takeaways

  • The App Router uses Server Components to reduce client-side JavaScript bundle sizes significantly.
  • Layouts in the App Router persist state during navigation, preventing unnecessary re-renders of global UI.
  • Streaming in the App Router allows for faster Time to First Byte (TTFB) by showing content as it becomes available.
  • The Pages Router is strictly file-system based, which becomes difficult to manage in complex applications compared to the App Router's directory-based nesting.

What is the fundamental difference in architecture?

The Pages Router relies on a flat file system where each file in the pages directory automatically becomes a route. This model served Next.js well for many years, providing a simple way to create pages by just placing a file in the directory. However, as applications scale, the folder structure can become difficult to maintain because all files live in a single directory. You often end up with complex configurations to handle shared layouts or common components that are not strictly routes.

The App Router introduces a directory-based architecture within the app folder. This structure uses specific, reserved file names such as layout.tsx, page.tsx, and loading.tsx to define the UI segments of your application. This directory-based approach allows you to co-locate components, styles, and data-fetching logic directly next to the routes they serve. By nesting directories, you naturally create hierarchical layouts. This hierarchy solves the problem of sharing UI elements across specific sub-sections of your application without causing global re-renders. Every segment of the route can have its own data requirements, providing better isolation and organization for large-scale applications.

How does data fetching differ between them?

In the Pages Router, data fetching is strictly bound to the page level. You rely on functions like getServerSideProps or getStaticProps to fetch all necessary data before the page is sent to the client. This requirement forces developers to fetch everything at the very top of the component tree, which can lead to waterfalls if the page requires data from multiple sources. The browser must wait for these functions to finish before it receives the initial HTML.

The App Router changes this model by using React Server Components. These components allow you to fetch data directly inside any component using standard async/await patterns. Because this happens on the server, you can perform database queries or fetch API data right where it is needed. This granularity enables streaming, where parts of the page can render and stream to the browser while other components are still waiting for their data. This drastically improves the perceived performance of the page, as the user sees the initial layout immediately while the rest of the content fills in as it finishes loading.

The following code demonstrates the shift from page-level blocking to component-level asynchronous fetching.

FeaturePages RouterApp Router
Data FetchingPage level onlyComponent level
Server ComponentsNoYes
StreamingLimitedBuilt-in
Shared LayoutsDifficultNative/Easy
// App Router: Fetch data directly in the component
export default async function Page() {
  const data = await getDashboardData();
  return <div>{data.title}</div>;
}

// Pages Router: Fetching is limited to the page level
export async function getServerSideProps() {
  const data = await getDashboardData();
  return { props: { data } };
}

Why does bundle size matter for performance?

The App Router shifts much of the heavy lifting to the server by using React Server Components. Code inside these components is never sent to the client browser, which means the JavaScript bundle size is significantly smaller compared to the Pages Router. When using heavy libraries like date-fns, markdown parsers, or complex utility functions, you can keep them on the server and only send the final HTML to the user.

Conversely, the Pages Router sends the entire component code to the client. Even if a library is only used to compute data for the server-side render, the client still receives that code. This leads to larger JavaScript payloads that the browser must parse and execute. This overhead directly impacts core web vitals, specifically Time to Interactive and First Input Delay. By moving logic to the server, you effectively remove the cost of that logic from the client's device, resulting in a snappier experience for users on slower hardware or mobile networks.

When is it appropriate to keep using the Pages Router?

You should consider sticking with the Pages Router if you are currently maintaining a large, stable project where the cost of migrating the existing codebase exceeds the benefits provided by modern features. If your application currently meets all performance goals and does not need frequent changes to the UI structure, there is little incentive to migrate just for the sake of following a trend. Stability is a valid architectural decision in enterprise environments.

There are also edge cases involving specific niche dependencies. If your application relies on older third-party libraries that are fundamentally incompatible with React Server Components or if your setup involves deep integrations with legacy patterns that the App Router does not support, the Pages Router remains a reliable choice. However, the ecosystem is moving rapidly toward Server Components, and most new packages are designed with the App Router in mind. You might find that keeping the Pages Router makes finding support or finding compatible libraries increasingly difficult over time.

What are the common hurdles when switching to the App Router?

The primary adjustment for developers moving to the App Router is learning how to work with the 'use client' directive. Developers often forget that interactive elements like buttons, event listeners, and React hooks (such as useState or useEffect) must be explicitly marked as client components. Without this directive, the component will attempt to run on the server, resulting in errors. Mastering the boundary between server-side and client-side code is the most critical skill for successfully building with the App Router.

Another point of confusion is state management. In the Pages Router, moving from one page to another often triggers a full page refresh, which resets state. In the App Router, layouts persist their state during navigation between nested pages. This means that if you have a sidebar or a global UI element, it does not re-mount when you navigate. While this is great for performance, it means you cannot rely on re-mounting to reset global state variables. You must instead handle your state transitions explicitly by managing your data stores properly within your components or using React context to reset values when necessary.

Frequently asked questions

Can I mix the App Router and Pages Router in one project?

Yes, Next.js allows you to have both folders simultaneously. This is a common strategy for incremental migration, allowing you to move pages one by one to the new directory structure while keeping the existing site functional.

Is the App Router harder to learn?

It has a steeper learning curve than the Pages Router because it introduces concepts like React Server Components and nested layouts. However, once you understand how to separate server and client logic, it leads to more maintainable and performant applications.

Should I migrate my existing app today?

You should only migrate if your application requires the features provided by the App Router, such as streaming or advanced layout management. If your app is simple and performant, there is no immediate pressure to migrate, but it is wise to start planning for the shift.

Sources & further reading

About the author

Tushar Gautam is a full-stack & ai product engineer in India. He builds AI SaaS products such as an AI video ad generator, a RAG chatbot platform and a Razorpay-powered report service, mostly with Next.js, Flask and the Gemini API. See the projects, GitHub or LinkedIn.

This article was drafted with the help of AI (Google Gemini) from official documentation and published by Tushar Gautam. Spotted an error? Let me know.