/    Sign up×
Bounties /Pin to ProfileBookmark

What is the difference between App Router and Pages Router in Next.js?

+ 4,000
Copy linkTweet thisAlerts:
Jul 26.2023

I read through all of this here: https://nextjs.org/docs/pages/building-your-application/upgrading/app-router-migration but what is the difference? What’s the tl;dr on why I should invest time in the new app router vs the existing pages router concepts in nextjs?

to post a answer
Next.js

2 Replies

Davinci•003 auto-replyThe App Router in Next.js is used to create routes for server-side rendered pages, while the Pages Router is used to create routes for client-side rendered pages. The App Router is used to create routes for API endpoints, while the Pages Router is used to create routes for pages. The App Router is used to create routes for dynamic pages, while the Pages Router is used to create routes for static pages.

The App Router is used to create routes for pages that require data fetching, while the Pages Router is used to create routes for pages that do not require data fetching. The App Router is used to create routes for pages that require authentication, while the Pages Router is used to create routes for pages that do not require authentication.

For example, the following code snippet shows how to use the App Router to create a route for a dynamic page:

[code]
// app.js

const express = require('express');
const next = require('next');

const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();

app.prepare().then(() => {
const server = express();

server.get('/dynamic-page', (req, res) => {
return app.render(req, res, '/dynamic-page

Was this helpful?

Copy linkTweet thisAlerts:
@AhmadassayyaafJul 29.2023 — However, based on the context of Next.js routing, here's a general explanation of what they might refer to:

Pages Router: In Next.js, the "Pages Router" generally refers to the built-in routing system that automatically maps pages based on the files present in the "pages" directory. Each file inside the "pages" directory represents a specific route, and the Next.js framework handles the routing for you. For example, if you have a file named about.js inside the "pages" directory, Next.js will automatically create a route for /about using that file.

App Router: The term "App Router" might refer to a custom router or routing logic implemented by developers within their Next.js application. This custom router can handle routing differently than the default Pages Router and might be used to implement more complex navigation, handle authentication, or integrate with external libraries or frameworks.Keep in mind that these explanations are speculative based on the common terminology related to routing in web applications. To get a precise understanding of "App Router" and "Pages Router" in the context of Next.js, I recommend checking the official Next.js documentation or any recent resources or discussions related to these terms.
×

Success!

Help @todd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...