Skip to main content

Route Segment Config

Route segment config options allow you to configure the behavior of a Page, Layout, or Route Handler by exporting constants.

Usage

Export configuration constants from page.tsx, layout.tsx, or route.ts:

Options

dynamic

Type: 'auto' | 'force-dynamic' | 'force-static' | 'error'
Default: 'auto'
Control static/dynamic rendering behavior.

Values

'auto' (default)
Automatic detection. Use static rendering unless dynamic APIs are called.
'force-dynamic'
Force dynamic rendering. Page is always server-rendered on each request.
Sets Cache-Control: private, no-cache, no-store, max-age=0, must-revalidate header.
'force-static'
Force static rendering. Page is rendered once at build time.
Sets Cache-Control: public, max-age=31536000, immutable header.
'error'
Throw error if dynamic APIs are used. Useful to ensure pages remain fully static.

revalidate

Type: number | false
Default: false
Time in seconds until the page is revalidated (ISR).

Values

false (default)
No revalidation. Cached indefinitely (or until manually invalidated).
0
No caching. Equivalent to dynamic = 'force-dynamic'.
number
Revalidate after N seconds. Uses stale-while-revalidate strategy:
  • Cached responses served instantly
  • Background revalidation triggered after expiry
  • New version served on next request after revalidation completes

Route Handlers

Route handlers support revalidate for ISR:
Sets Cache-Control: s-maxage=60, stale-while-revalidate header.

dynamicParams

Type: boolean
Default: true
Control behavior for dynamic routes not generated by generateStaticParams.

Values

true (default)
Dynamic segments not in generateStaticParams are generated on-demand.
false
Dynamic segments not in generateStaticParams return 404.

runtime

Not supported. vinext runs on a single runtime (Node.js dev server or Cloudflare Workers in production). This option is ignored.
Next.js uses this to switch between Node.js and Edge runtimes. vinext deploys everything to the same environment.

preferredRegion

Not supported. Cloudflare Workers deploy globally by default. This option is ignored.
Next.js uses this for Vercel’s regional deployments. On Cloudflare Workers, all code runs on the edge globally.

Combining Options

You can export multiple segment config options:

ISR with Cache Handler

For production ISR, set a cache handler:
See KV Cache Handler for details.

Cache-Control Headers

Route segment config automatically sets appropriate Cache-Control headers:

Type Safety

Import types for route segment config: