The App Router is the modern routing system in Next.js (v13+), designed to replace the older Pages Router. It provides file-based routing, nested layouts, server components, and advanced data fetching. Understanding it deeply helps build scalable, maintainable, and SEO-friendly applications.
Located in the app/ directory.
Each folder represents a route, and each page.js file represents the UI for that route.
Supports nested routes, dynamic routes, and layouts.
Fully compatible with React Server Components and client components.
Must include <html> and <body> tags.
Wraps all pages in the app.
Applies only to pages inside a folder.
Static routes: app/about/page.js → /about
Dynamic routes: [slug]/page.js → /blog/my-post
Catch-all routes: [...slug]/page.js → /docs/react/hooks
Optional catch-all: [[...slug]]/page.js → /docs or /docs/react
Supports server-side fetching in pages and layouts:
Server Components: Default; fetch data on server.
Static Rendering: Default for fetch with no cache options.
Dynamic Rendering: cache: 'no-store'
Incremental Static Regeneration (ISR): next: { revalidate: 60 }
Example:
Server Components (default in App Router):
Rendered on the server
Can fetch data directly
Do not include JS in client bundle
Client Components:
Marked with 'use client'
Needed for interactivity, hooks, and browser APIs
Use error.js in any folder to catch route-specific errors.
not-found.js for 404 pages.
Use loading.js for skeleton UI while page or layout loads.
Supports React Suspense for streaming UI.
Located under app/api/.../route.js
Support HTTP methods like GET, POST, PUT, DELETE
| Feature | Pages Router | App Router |
|---|---|---|
| Layouts | Limited | Nested layouts |
| Data fetching | getServerSideProps / getStaticProps | Direct fetch() in server components |
| Server components | ❌ | ✅ (default) |
| Streaming UI | ❌ | ✅ with Suspense |
| File-based API | pages/api | app/api/route.js |
Use nested layouts for shared UI
Prefer server components for data fetching
Use client components only when needed
Organize routes cleanly with folders
Use error.js and loading.js for better UX
Leverage dynamic and catch-all routes for flexible URLs
The App Router is a powerful upgrade in Next.js that combines routing, layouts, data fetching, and server-side rendering seamlessly. Mastering it allows you to build modern, scalable, and SEO-friendly web applications efficiently.
Take quizzes related to this topic and see where you stand!
Start Quiz Now