Next.js Discord

Discord Forum

What's actually the diff between app and page router?

Unanswered
Virginia's Warbler posted this in #help-forum
Open in Discord
Virginia's WarblerOP
Seems like both routers are based on nest folders in the project's filesystem. What is the real difference?
Also, I tried reading about it online, but one part I dont understand (screenshot). I dont see "JavaScript API within an app directory". What does it mean by "JavaScript API"?

10 Replies

App router uses the latest react features, features from react canary. This includes <Suspense>, RSC, useFormState and so on

The pages router is more stable, using the stale react version, without RSC. This means that components are by nature are client-components.
Generally both app and pages supports the core rendering feature of Next.js: server side rendering, static site generation, and incremental site generation
But it starts to differ interms of the mental model of the way react canary does things compared to the stable react version (pre-react 18).

You get more experimental features such as <Suspense>, Server Actions, and so on that adds to the features of existing ones that are absent in Pages Routing
The main difference in terms of rendering is that app router partially renders the routes. And this can hamper the ability to have inter-page animations, unlike the pages dir. However this in itself is some might argue, the cost of being "efficient" with the bandwidth and et cetera.

Some people I know prefer pages routing because they have a more control interms of inter-page behavior such as transitions and route change events.

But there are lots more features that enables better DX and saves cost in terms of bandwidth and load with the introduction of the App dir.

Here is some but not all features:

- partial rendering: only render the child segment that changes without resetting the state of the layout

- react server component: compose react component in the server, render them before it is being hydrated in the client

- suspense: component level loading state and promise handling

- server actions: instant server endpoint that is created at build time, used like a regular function in the client .

- etc: useOptimistic, useActionState, useFormStatus, <form action={}>, react-compiler, unstable_cache(), and many more. These are all just the ones that i remember for now lol
Virginia's WarblerOP
Regarding this:
The pages router is more stable, using the stale react version, without RSC. This means that components are by nature are client-components.
I thought every Next components are server side by default, unless you make it client-side by writing at the top "use client"
@ᴉuɐpɹɐɐ ?