Route Segment Config

Learn about how to configure options for Next.js route segments.

Good to know:

  • The dynamic, revalidate, and fetchCache options are not available when Cache Components is enabled. See Caching and Revalidating (Previous Model) for their documentation.
  • Route Segment options only take effect in Server Component Pages, Layouts, or Route Handlers.
  • generateStaticParams cannot be used inside a 'use client' file.

The Route Segment options allow you to configure the behavior of a Page, Layout, or Route Handler by directly exporting the following variables:

OptionTypeDefault
dynamicParamsbooleantrue
runtime'nodejs' | 'edge''nodejs'
preferredRegion'auto' | 'global' | 'home' | string | string[]'auto'
maxDurationnumberSet by deployment platform

Options

dynamicParams

Control what happens when a dynamic segment is visited that was not generated with generateStaticParams.

export const dynamicParams = true // true | false
  • true (default): Dynamic segments not included in generateStaticParams are generated on demand.
  • false: Dynamic segments not included in generateStaticParams will return a 404.

Good to know:

  • This option replaces the fallback: true | false | blocking option of getStaticPaths in the pages directory.
  • To statically render all paths the first time they're visited, you'll need to return an empty array in generateStaticParams or use export const dynamic = 'force-static'.
  • When dynamicParams = true, the segment uses Streaming Server Rendering.

runtime

Use the Node.js runtime for rendering your application. This option cannot be used in Proxy.

Good to know: Using runtime: 'edge' is not supported for Cache Components.

export const runtime = 'nodejs'
// 'nodejs' | 'edge'
  • 'nodejs' (default)
  • 'edge'

preferredRegion

export const preferredRegion = 'auto'
// 'auto' | 'global' | 'home' | ['iad1', 'sfo1']

Support for preferredRegion, and regions supported, is dependent on your deployment platform.

Good to know:

  • If a preferredRegion is not specified, it will inherit the option of the nearest parent layout.
  • The root layout defaults to all regions.

maxDuration

By default, Next.js does not limit the execution of server-side logic (rendering a page or handling an API). Deployment platforms can use maxDuration from the Next.js build output to add specific execution limits.

Note: This setting requires Next.js 13.4.10 or higher.

export const maxDuration = 5

Good to know:

  • If using Server Actions, set the maxDuration at the page level to change the default timeout of all Server Actions used on the page.

generateStaticParams

The generateStaticParams function can be used in combination with dynamic route segments to define the list of route segment parameters that will be statically generated at build time instead of on-demand at request time.

See the API reference for more details.

Version History

Version
v16.0.0export const experimental_ppr = true removed. A codemod is available.
v15.0.0-RCexport const runtime = "experimental-edge" deprecated. A codemod is available.

On this page