Skip to main content
Frontend Engineering

Next.js 15 App Router & Server Actions

Essential

App Router file conventions, Server Actions ('use server'), static metadata, generateStaticParams, caching, and redirects.

Instant Copy & SearchProduction Flagged SyntaxCurrent Flag Reference

Next.js 15 App Router & Server Actions Interactive Command Directory

Browse, search, and copy battle-tested commands & syntax recipes (16 Total Commands).

16+ Verified Recipes
Static Export Configdynamic = 'force-static'
export const dynamic = 'force-static'; export const revalidate = false;

Enforce pure zero-cost static HTML page generation at build time.

Static Path GenerationgenerateStaticParams()
export async function generateStaticParams() { const items = await getItems(); return items.map(item => ({ slug: item.slug })); }

Pre-render dynamic route parameters statically at build time.

Dynamic SEO MetadatagenerateMetadata()
export async function generateMetadata({ params }): Promise<Metadata> { const { slug } = await params; return { title: `${slug} Reference | HelloAIHub`, alternates: { canonical: `https://www.helloaihub.tech/${slug}` } }; }

Generate canonical SEO metadata and OpenGraph tags dynamically.

Server Action'use server', revalidatePath
'use server'; export async function updateProfile(formData: FormData) { const email = formData.get('email'); await db.updateUser(email); revalidatePath('/profile'); }

Execute secure server-side mutation callable directly from client forms.

Navigation & RedirectspermanentRedirect, notFound
import { permanentRedirect, notFound } from 'next/navigation'; if (!data) notFound(); permanentRedirect('/new-location');

Trigger HTTP 308 permanent redirect or render 404 error page.

Optimized Image<Image priority />
<Image src="/hero.png" alt="Architecture" width={800} height={400} priority={true} />

Automatically convert images to WebP/AVIF with responsive sizing and layout shift prevention.

Incremental Static Regenerationexport const revalidate
export const revalidate = 3600; // Revalidate page in background every 1 hour

Configure background revalidation interval regenerating static pages automatically upon request.

On-Demand RevalidationrevalidatePath, revalidateTag
revalidatePath('/blog/[slug]', 'page'); revalidateTag('products');

Purge and refresh specific server cache paths and tagged data fetches on demand.

Edge MiddlewareNextResponse.redirect
export function middleware(request: NextRequest) { const token = request.cookies.get('token'); if (!token) return NextResponse.redirect(new URL('/login', request.url)); }

Execute lightweight code before requests complete to rewrite paths, redirect, or verify cookies.

Route HandlersNextResponse.json
export async function GET(request: NextRequest) { return NextResponse.json({ status: 'healthy' }, { status: 200 }); }

Create Web API endpoints returning JSON using standard Web Request and Response objects.

Server Headers & Cookiescookies(), headers()
import { headers, cookies } from 'next/headers'; const cookieStore = await cookies(); const headerList = await headers();

Asynchronously read incoming HTTP headers and cookie tokens inside Server Components.

CMS Draft ModedraftMode()
import { draftMode } from 'next/headers'; const { isEnabled } = await draftMode();

Bypass static data caches to render live unpublished preview drafts for content editors.

Server StreamingSuspense, streaming
<Suspense fallback={<CardSkeleton />}> <SlowStreamingComponent /> </Suspense>

Progressively stream rendered HTML chunks from the server as slow backend fetches resolve.

Route InterceptionParallel & Intercepting Routes
// app/feed/@modal/(..)photo/[id]/page.tsx

Intercept routes to render contextual modals while maintaining shareable deep-link URLs.

Script Optimizationnext/script
<Script src='https://www.googletagmanager.com/gtag/js' strategy='afterInteractive' />

Load third-party analytics scripts with optimized browser execution priorities.

Bundle Profiling--profile
npm run build -- --profile

Profile Next.js production build bundle sizes and detect large dependencies.

Zero Setup100% In-Browser Execution

Companion Developer Tools & Playgrounds

Accelerate command execution and syntax debugging with HelloAIHub suite of interactive tools.

Explore all developer tools

Next.js 15 App Router & Server Actions: Command Groups & Quick Index

16 indexed entries across 16 sections
Static Export Config1 items
Static Path Generation1 items
Dynamic SEO Metadata1 items
Server Action1 items
Navigation & Redirects1 items
Optimized Image1 items
Incremental Static Regeneration1 items
On-Demand Revalidation1 items
Edge Middleware1 items
Route Handlers1 items
Server Headers & Cookies1 items
CMS Draft Mode1 items
Server Streaming1 items
Route Interception1 items
Script Optimization1 items
Bundle Profiling1 items

Highlighted Flags & Syntax Examples in Next.js 15 App Router & Server Actions

export const dynamic = 'force-static'; export const revalidate = false;

Enforce pure zero-cost static HTML page generation at build time.

Flags: dynamic = 'force-static'
export async function generateStaticParams() { const items = await getItems(); return items.map(item => ({ slug: item.slug })); }

Pre-render dynamic route parameters statically at build time.

Flags: generateStaticParams()
export async function generateMetadata({ params }): Promise<Metadata> { const { slug } = await params; return { title: `${slug} Reference | HelloAIHub`, alternates: { canonical: `https://www.helloaihub.tech/${slug}` } }; }

Generate canonical SEO metadata and OpenGraph tags dynamically.

Flags: generateMetadata()
'use server'; export async function updateProfile(formData: FormData) { const email = formData.get('email'); await db.updateUser(email); revalidatePath('/profile'); }

Execute secure server-side mutation callable directly from client forms.

Flags: 'use server', revalidatePath

Frequently Asked Questions

Expert recommendations, common traps, and production best practices for Next.js 15 App Router & Server Actions.

What is the difference between dynamic = 'force-static' and 'force-dynamic'?

'force-static' forces Next.js to render the page to static HTML at build time, caching all fetch requests permanently. 'force-dynamic' disables caching completely, running the route handler on every single incoming HTTP request on the server.

Why must dynamic route params be awaited in Next.js 15?

In Next.js 15, route parameters and searchParams were transitioned to asynchronous Promises (e.g. const { slug } = await params) to allow the framework to optimize streaming and start rendering page shells before parameters finish resolving.

What is Incremental Static Regeneration (ISR) and how does stale-while-revalidate caching work?

ISR allows you to update static pages in the background without rebuilding your entire site. When a request arrives after the 'revalidate' window has elapsed, Next.js immediately serves the cached 'stale' static HTML page to the user while asynchronously generating the fresh page in the background for subsequent visitors.

How do React Server Components (RSC) and Client Components ('use client') interoperate in the App Router?

By default, all components in the App Router are Server Components: they run exclusively on the server, have direct database access, and send 0 bytes of JavaScript to the browser. Adding 'use client' marks a component boundary where JavaScript is sent to the client for interactivity (useState, event listeners). Server Components can import Client Components, and can pass Server Components as children into Client Components.

What is the difference between revalidatePath and revalidateTag in Next.js caching?

'revalidatePath' purges the cached HTML and data associated with a specific URL route (e.g. '/products/123'). 'revalidateTag' purges only the specific fetch requests tagged with that cache tag (e.g. 'fetch(..., { next: { tags: ['products'] } })'), regardless of which pages consume that data.

How does Partial Prerendering (PPR) combine static and dynamic rendering in Next.js?

PPR serves a static HTML shell instantly from the edge (headers, layouts, fallback skeletons), while streaming dynamic personalized content (user carts, recommendations) into Suspense holes in the same HTTP connection, delivering the speed of static sites with the flexibility of server rendering.

Cross-Hub Skill Acceleration

Combine command lookups with active coding interviews and complete career paths.

Need More Cheat Sheets?

Explore developer cheat sheets and syntax guides on HelloAIHub.

Browse All Cheat Sheets