The full-stack framework built on React. App Router, server/client components, data caching, server actions, Route Handlers, middleware, metadata and SEO, streaming, and deployment β learn the standard of modern web development from end to end.
Intermediate
Updated Oct 1, 2026
~7 min read
15 sections
14 code examples
Web IDE lab included
β²
Next.js Web IDE
Run code in the browser with nothing to install and learn through step-by-step examples.
The full-stack framework built on React. App Router, server/client components, data caching, server actions, Route Handlers, middleware, metadata and SEO, streaming, and deployment β learn the standard of modern web development from end to end. Rather than listing concepts, this guide is organized so you can follow the content in the order you have to make decisions on a real project.
Key perspective
Frontend / app development
Do not stop at drawing the screen: look at state, data requests, routing, accessibility, and the unit of deployment together.
To make what you read stick, it helps to capture the flow as a picture first. The two diagrams below are reference maps you can keep coming back to while learning Next.js.
Learning flow
Rendering diagramβ¦
Architecture view
Rendering diagramβ¦
What is Next.js?
When you first open Next.js, the big picture matters more than individual commands. This section starts with the problems the concepts ahead were created to solve.
Next.js is a full-stack framework that bundles routing, rendering strategies, data fetching, and deployment on top of React. The key is that the rendering mode can be chosen differently per page and per component rather than for the whole app.
Rendering
Description
When to use it
SSG
Static HTML generated at build time
Content that rarely changes
ISR
Static + periodic revalidation
Blogs, product lists
SSR
Server rendering on every request
Pages personalized per user
CSR
Client rendering
Interactive dashboards
App Router & file-based routing
Here you look at App Router & file-based routing alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
The folder structure of the app/ directory is the URL. Inside a folder, only page.tsx is exposed as an actual route, and the other files (layout, loading, error, and so on) are wired up automatically by convention.
catch-all β matches several segments as an array
[[...slug]]
optional catch-all β also matches the parent path itself
(marketing)
route group β a folder group that does not appear in the URL path
@modal
parallel route β renders several pages in the same layout at once
(.)photo
intercepting route β intercepts another route, for modals and the like
Server vs client components
Here you look at Server vs client components alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
Server components are the default. Declare "use client" with the smallest possible scope, only on leaf components that need state, events, or browser APIs.
TSX
// Server component (default) β can access the DB directlyasync function ProductList() { const products = await db.product.findMany({ take: 20 }); return <ul>{products.map(p => <li key={p.id}>{p.name}</li>)}</ul>;}// Client component β when interaction is needed'use client';import { useState } from 'react';export function Counter() { const [n, setN] = useState(0); return <button onClick={() => setN(n+1)}>{n}</button>;}
Data fetching & caching
Here you look at Data fetching & caching alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
Next.js extends fetch to control caching declaratively. The default is static (cached indefinitely), and options select periodic revalidation or fully dynamic rendering.
TSX
// Default β cached indefinitely (behaves like SSG)const res = await fetch('https://api.example.com/products');// ISR β revalidated in the background every N secondsconst res2 = await fetch(url, { next: { revalidate: 60 } });// Tag-based revalidation β selectively invalidate specific data onlyconst res3 = await fetch(url, { next: { tags: ['products'] } });// later, in a server action and so on: revalidateTag('products');// Fetch fresh on every request (SSR)const res4 = await fetch(url, { cache: 'no-store' });// Force dynamic rendering for the whole routeexport const dynamic = 'force-dynamic';
Option
Behavior
(default, no option)
Cached at build time, reused until revalidated
next: { revalidate: N }
Revalidated in the background after N seconds (ISR)
next: { tags: [...] }
Selectively invalidate specific caches with revalidateTag()
cache: 'no-store'
Fetch fresh on every request (same as SSR)
export const dynamic = 'force-dynamic'
Server-render the whole page on every request
Server actions & forms
Here you look at Server actions & forms alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
A server action is a server function that can be called directly from the client. It handles form submissions and mutations with no separate API route. Just add the `use server` directive and the function body runs on the server, and in a client component useActionState hands you the loading and error state of that function to reflect in the form UI, so no separate fetch or state management code is needed.
app/users/actions.tsTSX
'use server';import { revalidatePath } from 'next/cache';import { z } from 'zod';const schema = z.object({ name: z.string().min(1, 'Enter a name') });export async function createUser(prevState: { error?: string }, formData: FormData) { const parsed = schema.safeParse({ name: formData.get('name') }); if (!parsed.success) { return { error: parsed.error.issues[0].message }; } await db.user.create({ data: parsed.data }); revalidatePath('/users'); return { error: undefined };}
Here you look at Route Handlers (API) alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
Where server actions are for forms and mutations, a Route Handler is for REST APIs exposed externally and for receiving webhooks. Export a function per HTTP method in app/api/**/route.ts.
app/api/users/[id]/route.tsTYPESCRIPT
import { NextRequest, NextResponse } from 'next/server';export async function GET(_req: NextRequest, { params }: { params: Promise<{ id: string }> }) { const { id } = await params; const user = await db.user.findUnique({ where: { id } }); if (!user) return NextResponse.json({ error: 'not found' }, { status: 404 }); return NextResponse.json(user);}export async function DELETE(_req: NextRequest, { params }: { params: Promise<{ id: string }> }) { const { id } = await params; await db.user.delete({ where: { id } }); return new NextResponse(null, { status: 204 });}
Situation
Choice
Form submission/mutation within the same app
Server Action
A REST API called by external clients (mobile apps and so on)
Route Handler
Receiving webhooks (payments, GitHub, and so on)
Route Handler
When a streaming response is needed outside server components
Route Handler
Middleware
Here you look at Middleware alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
Middleware runs before a request reaches a route. Use it for authentication checks, redirects, rewrites, and header manipulation, and narrow its scope with a matcher.
Here you look at Metadata & SEO alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
Generate the title/description/OG tags per page dynamically with generateMetadata, and control search engine crawling with sitemap.ts and robots.ts.
Here you look at Loading/Error UI & streaming alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
loading.tsx, error.tsx, and not-found.tsx each replace a Suspense fallback, an Error Boundary, and 404 handling with a single file. Wrap only the data that is ready late in and the rest of the screen is streamed first.
TEXT
app/dashboard/
βββ layout.tsx
βββ page.tsx
βββ loading.tsx # shown automatically while page.tsx gets ready
βββ error.tsx # catches errors thrown below it (needs use client)
βββ not-found.tsx # shown when notFound() is called
Here you look at Image & font optimization alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
next/image handles resizing, format conversion (WebP/AVIF), and lazy loading automatically, and next/font self-hosts fonts at build time to eliminate layout shift (CLS).
TSX
import Image from 'next/image';import { Inter } from 'next/font/google';const inter = Inter({ subsets: ['latin'], display: 'swap' });export default function Hero() { return ( <main className={inter.className}> <Image src="/hero.png" alt="Product introduction image" width={1200} height={600} priority // only for the LCP image /> </main> );}
Deployment (Vercel / Cloudflare)
Here you look at Deployment (Vercel / Cloudflare) alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
Vercel supports 100% of the App Router features with no extra configuration. On Cloudflare, deploy to Workers/Pages with the OpenNext adapter.
The maker of Next.js; full support for every feature, including ISR, Edge, and image optimization
Cloudflare Workers/Pages
Deployed with @opennextjs/cloudflare; low latency and low cost
Docker (self-hosted)
Set output: 'standalone' in next.config.ts, then build a lightweight image
Next.js practical design
Next.js practical design is a point where the options diverge. Using the table to compare what each approach is for and how it differs in operation makes later decisions much easier.
The key in Next.js is designing the server/client boundary in the App Router. State where data is fetched and the cache policy explicitly per page.
Decision point
Question to ask
Practical guideline
Boundaries
Which parts of the Next.js code are most likely to change?
Separate input/output, configuration, external integrations, and the core rules.
State
Where is state created and where does it go away?
Make the owner and lifecycle of state visible in the code.
Failure
What does the caller receive on failure?
Decide the timeout, fallback, and error contract first.
Next.js operating standards
This section covers Next.js operating standards from a practical perspective. Instead of memorizing the concept, focus on the situations in which you would reach for it.
Make ISR/revalidate, dynamic routes, edge/runtime differences, bundle splitting, and image optimization your operating standards.
Next.js verification strategy
Next.js verification strategy is a point where the options diverge. Using the table to compare what each approach is for and how it differs in operation makes later decisions much easier.
Test route handlers, metadata, the sitemap, canonical URLs, and hydration mismatches.
Quality axis
How to verify
Definition of done
Correctness
Automate the normal/failure cases.
The core scenarios pass reproducibly.
Regression prevention
When fixing a bug, leave the same case behind as a test.
The same failure is not deployed again.
Operability
Check the logs, metrics, and alerts.
There is a path for tracing the cause when a problem occurs.
Next.js: frequently asked questions
What is the difference between Next.js and React?
React is a library for building screens from components, and Next.js is a framework that adds routing, server rendering, build optimization, and API handling on top. What you would have to assemble yourself with React alone, Next.js provides in a defined way.
Should I use the App Router or the Pages Router?
For a new project, the App Router is recommended. Server components, nested layouts, and streaming are provided through the App Router. Existing projects on the Pages Router remain supported, so there is no rush to move, and the two can coexist in one project while you migrate gradually.
How do I decide between server components and client components?
A server component runs only on the server, can access databases and secrets directly, and sends no JavaScript to the browser. Parts that need state, event handlers, or browser APIs become client components by putting "use client" at the top of the file. Default to server components and split out only the small interactive parts as client components.
Next steps
This section covers Next steps from a practical perspective. Instead of memorizing the concept, focus on the situations in which you would reach for it.
π
Finished the Next.js fundamentals?
Hooks inside components, state management, form validation, and performance optimization are covered in more depth in the React guide. For a large codebase, add type safety with the TypeScript guide, and for automating the deployment pipeline see the CI/CD guide.