Route Segment Config
Learn about how to configure options for Next.js route segments.
Good to know:
- The
dynamic,revalidate, andfetchCacheoptions 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.
generateStaticParamscannot 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:
| Option | Type | Default |
|---|---|---|
dynamicParams | boolean | true |
runtime | 'nodejs' | 'edge' | 'nodejs' |
preferredRegion | 'auto' | 'global' | 'home' | string | string[] | 'auto' |
maxDuration | number | Set by deployment platform |
Options
dynamicParams
Control what happens when a dynamic segment is visited that was not generated with generateStaticParams.
true(default): Dynamic segments not included ingenerateStaticParamsare generated on demand.false: Dynamic segments not included ingenerateStaticParamswill return a 404.
Good to know:
- This option replaces the
fallback: true | false | blockingoption ofgetStaticPathsin thepagesdirectory. - To statically render all paths the first time they're visited, you'll need to return an empty array in
generateStaticParamsor useexport 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.
'nodejs'(default)'edge'
preferredRegion
Support for preferredRegion, and regions supported, is dependent on your deployment platform.
Good to know:
- If a
preferredRegionis not specified, it will inherit the option of the nearest parent layout. - The root layout defaults to
allregions.
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.
Good to know:
- If using Server Actions, set the
maxDurationat 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.