14

I have started learning next.js in Next.js official documentation:

next.js official document

The document mentions two router features; App Router and Pages Router. Which one is best for development?

Can anyone explain the difference between App Router and Pages Router?

Should I learn both or one?

Sabuncu
  • 5,095
  • 5
  • 55
  • 89
Ragu
  • 772
  • 9
  • 29
  • 3
    Some info here [Next.js’s New App Vs. Pages Router: A Detailed Comparison](https://javascript.plainenglish.io/next-jss-new-app-vs-pages-router-a-detailed-comparison-46f846963af5) – kiranvj Jun 28 '23 at 05:16

4 Answers4

12

Well to easily understand it, I have created the below table of difference, based on your requirement you can use desired router however app router is prefered in the official docs.

Feature App Router Pages Router
Routing type Server-centric Client-side
Support for Server Components Yes No
Complexity More complex Simpler
Performance Better Worse
Flexibility More flexible Less flexible

Also refer latest Nextjs 13 code templates Next.js 13+ Power Snippets | TypeScript/Javascript

It includes wide range of code snippets for both ts and js. Find all snippets here


krishnaacharyaa
  • 14,953
  • 4
  • 49
  • 88
3

In Next.js, there are two types of routers: the App router and the Page router. Let's discuss the differences between them point by point:

Purpose:

  1. App Router: The App router handles the overall routing and navigation for your entire application. It is responsible for rendering the correct pages based on the URL and managing the transitions between pages.
  2. Page Router: The Page router handles the routing within individual pages of your application. It allows you to define dynamic routes and access the route parameters for rendering specific content on a page.

Location:

  1. App Router: The App router is typically implemented in the _app.js or _app.tsx file. It wraps your entire application and controls the routing and layout for all pages.
  2. Page Router: The Page router is implemented in each individual page component. It defines the routing logic and determines the content to be rendered based on the current route.


    In short, the App router is responsible for the overall routing and navigation of your application, while the Page router focuses on routing within individual pages. The App router is configured in the _app.js or _app.tsx file and provides global routing functionality, whereas the Page router is implemented within each page component and handles routing specific to that page.
ANOOP NAYAK
  • 473
  • 5
  • 8
0

Hello,

As explained and visually illustrated above, using app routing offers many improvements. As a developer, I would strongly recommend that you start your projects directly with app routing. I myself am currently in the process of converting my existing projects to this method, as are many others in our company.

Have fun developing and coding!

Nikoll
  • 1
-4

The App Router (_app.js) is used to configure app-wide settings and components, such as headers and footers. The Pages Router (files in the pages directory) is used to define routes and handle individual page rendering, including dynamic routes. You generally need to learn both to complete a full application.

bhogan2017
  • 50
  • 3