Route Segment Config

Per-Route Tuning — dynamic, revalidate, runtime

Route Segment Config

Each route file can export constants like dynamic, revalidate, and runtime to opt into specific rendering and caching behavior.

4 min read Level 3/5 #nextjs#route-segments#config
What you'll learn
  • Export `const dynamic` to force static or dynamic rendering
  • Export `const revalidate` to enable ISR
  • Export `const runtime` to pick Edge or Node.js

Route segment config is a set of named exports Next.js looks for in your page.tsx, layout.tsx, or route.ts. Each one tweaks how that segment is built and served.

dynamic — Force Static or Dynamic

// app/blog/[slug]/page.tsx
export const dynamic = 'force-static';

export default async function PostPage({
  params,
}: {
  params: Promise<{ slug: string }>;
}) {
  const { slug } = await params;
  const post = await fetchPost(slug);
  return <article>{post.title}</article>;
}
  • 'auto' (default) — Next.js infers based on data dependencies
  • 'force-static' — always static, errors if you read dynamic data
  • 'force-dynamic' — always render on every request
  • 'error' — like auto, but error out if dynamic data is encountered

revalidate — ISR

// regenerate this page at most once every 60 seconds
export const revalidate = 60;

revalidate enables Incremental Static Regeneration. The first request after the window serves the cached page and triggers a background rebuild.

runtime — Edge or Node

// app/api/echo/route.ts
export const runtime = 'edge';

export async function GET(request: Request) {
  return Response.json({ ip: request.headers.get('x-forwarded-for') });
}
  • 'nodejs' (default) — full Node APIs, slower cold start
  • 'edge' — V8 isolates, fast cold start, no Node APIs

The Other Knobs

A few more segment exports round out the API:

  • fetchCache — override the default fetch cache mode
  • preferredRegion — geographic hint for the edge runtime
  • maxDuration — function timeout in seconds (Vercel)
  • dynamicParams — control behavior for unknown generateStaticParams values

These exports compose. Most routes do not need any of them; reach for them when you are tuning a specific page’s caching or runtime behavior.

That wraps the routing section. Next we dive into Server Components.

React Server Components →