Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Important
Security Advisory: React2Shell & two new vulnerabilities
Find out more

Route Segment Config

Last updated October 23, 2025

Good to know:

  • The options outlined on this page are disabled if thecacheComponents flag is on, and will eventually be deprecated in the future.
  • 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 allows you to configure the behavior of aPage,Layout, orRoute Handler by directly exporting the following variables:

OptionTypeDefault
dynamic'auto' | 'force-dynamic' | 'error' | 'force-static''auto'
dynamicParamsbooleantrue
revalidatefalse | 0 | numberfalse
fetchCache'auto' | 'default-cache' | 'only-cache' | 'force-cache' | 'force-no-store' | 'default-no-store' | 'only-no-store''auto'
runtime'nodejs' | 'edge''nodejs'
preferredRegion'auto' | 'global' | 'home' | string | string[]'auto'
maxDurationnumberSet by deployment platform

Options

dynamic

Change the dynamic behavior of a layout or page to fully static or fully dynamic.

layout.tsx | page.tsx | route.ts
exportconstdynamic='auto'// 'auto' | 'force-dynamic' | 'error' | 'force-static'

Good to know: The new model in theapp directory favors granular caching control at thefetch request level over the binary all-or-nothing model ofgetServerSideProps andgetStaticProps at the page-level in thepages directory. Thedynamic option is a way to opt back in to the previous model as a convenience and provides a simpler migration path.

  • 'auto' (default): The default option to cache as much as possible without preventing any components from opting into dynamic behavior.

  • 'force-dynamic': Forcedynamic rendering, which will result in routes being rendered for each user at request time. This option is equivalent to:

    • Setting the option of everyfetch() request in a layout or page to{ cache: 'no-store', next: { revalidate: 0 } }.
    • Setting the segment config toexport const fetchCache = 'force-no-store'
  • 'error': Force static rendering and cache the data of a layout or page by causing an error if any components useDynamic APIs or uncached data. This option is equivalent to:

    • getStaticProps() in thepages directory.
    • Setting the option of everyfetch() request in a layout or page to{ cache: 'force-cache' }.
    • Setting the segment config tofetchCache = 'only-cache'.
  • 'force-static': Force static rendering and cache the data of a layout or page by forcingcookies,headers() anduseSearchParams() to return empty values. It is possible torevalidate,revalidatePath, orrevalidateTag, in pages or layouts rendered withforce-static.

Good to know:

  • Instructions onhow to migrate fromgetServerSideProps andgetStaticProps todynamic: 'force-dynamic' anddynamic: 'error' can be found in theupgrade guide.

dynamicParams

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

layout.tsx | page.tsx
exportconstdynamicParams=true// true | false
  • true (default): Dynamic segments not included ingenerateStaticParams are generated on demand.
  • false: Dynamic segments not included ingenerateStaticParams will return a 404.

Good to know:

  • This option replaces thefallback: true | false | blocking option ofgetStaticPaths in thepages directory.
  • To statically render all paths the first time they're visited, you'll need to return an empty array ingenerateStaticParams or utilizeexport const dynamic = 'force-static'.
  • WhendynamicParams = true, the segment usesStreaming Server Rendering.

revalidate

Set the default revalidation time for a layout or page. This option does not override therevalidate value set by individualfetch requests.

layout.tsx | page.tsx | route.ts
exportconstrevalidate=false// false | 0 | number
  • false (default): The default heuristic to cache anyfetch requests that set theircache option to'force-cache' or are discovered before aDynamic API is used. Semantically equivalent torevalidate: Infinity which effectively means the resource should be cached indefinitely. It is still possible for individualfetch requests to usecache: 'no-store' orrevalidate: 0 to avoid being cached and make the route dynamically rendered. Or setrevalidate to a positive number lower than the route default to increase the revalidation frequency of a route.
  • 0: Ensure a layout or page is alwaysdynamically rendered even if no Dynamic APIs or uncached data fetches are discovered. This option changes the default offetch requests that do not set acache option to'no-store' but leavesfetch requests that opt into'force-cache' or use a positiverevalidate as is.
  • number: (in seconds) Set the default revalidation frequency of a layout or page ton seconds.

Good to know:

  • The revalidate value needs to be statically analyzable. For examplerevalidate = 600 is valid, butrevalidate = 60 * 10 is not.
  • The revalidate value is not available when usingruntime = 'edge'.
  • In Development, Pages arealways rendered on-demand and are never cached. This allows you to see changes immediately without waiting for a revalidation period to pass.

Revalidation Frequency

  • The lowestrevalidate across each layout and page of a single route will determine the revalidation frequency of theentire route. This ensures that child pages are revalidated as frequently as their parent layouts.
  • Individualfetch requests can set a lowerrevalidate than the route's defaultrevalidate to increase the revalidation frequency of the entire route. This allows you to dynamically opt-in to more frequent revalidation for certain routes based on some criteria.

fetchCache

This is an advanced option that should only be used if you specifically need to override the default behavior.

By default, Next.jswill cache anyfetch() requests that are reachablebefore anyDynamic APIs are used andwill not cachefetch requests that are discoveredafter Dynamic APIs are used.

fetchCache allows you to override the defaultcache option of allfetch requests in a layout or page.

layout.tsx | page.tsx | route.ts
exportconstfetchCache='auto'// 'auto' | 'default-cache' | 'only-cache'// 'force-cache' | 'force-no-store' | 'default-no-store' | 'only-no-store'
  • 'auto' (default): The default option to cachefetch requests before Dynamic APIs with thecache option they provide and not cachefetch requests after Dynamic APIs.
  • 'default-cache': Allow anycache option to be passed tofetch but if no option is provided then set thecache option to'force-cache'. This means that evenfetch requests after Dynamic APIs are considered static.
  • 'only-cache': Ensure allfetch requests opt into caching by changing the default tocache: 'force-cache' if no option is provided and causing an error if anyfetch requests usecache: 'no-store'.
  • 'force-cache': Ensure allfetch requests opt into caching by setting thecache option of allfetch requests to'force-cache'.
  • 'default-no-store': Allow anycache option to be passed tofetch but if no option is provided then set thecache option to'no-store'. This means that evenfetch requests before Dynamic APIs are considered dynamic.
  • 'only-no-store': Ensure allfetch requests opt out of caching by changing the default tocache: 'no-store' if no option is provided and causing an error if anyfetch requests usecache: 'force-cache'
  • 'force-no-store': Ensure allfetch requests opt out of caching by setting thecache option of allfetch requests to'no-store'. This forces allfetch requests to be re-fetched every request even if they provide a'force-cache' option.

Cross-route segment behavior

  • Any options set across each layout and page of a single route need to be compatible with each other.
    • If both the'only-cache' and'force-cache' are provided, then'force-cache' wins. If both'only-no-store' and'force-no-store' are provided, then'force-no-store' wins. The force option changes the behavior across the route so a single segment with'force-*' would prevent any errors caused by'only-*'.
    • The intention of the'only-*' and'force-*' options is to guarantee the whole route is either fully static or fully dynamic. This means:
      • A combination of'only-cache' and'only-no-store' in a single route is not allowed.
      • A combination of'force-cache' and'force-no-store' in a single route is not allowed.
    • A parent cannot provide'default-no-store' if a child provides'auto' or'*-cache' since that could make the same fetch have different behavior.
  • It is generally recommended to leave shared parent layouts as'auto' and customize the options where child segments diverge.

runtime

We recommend using the Node.js runtime for rendering your application. This option cannot be used inProxy.

Good to know: Usingruntime: 'edge' isnot supported for Cache Components.

layout.tsx | page.tsx | route.ts
exportconstruntime='nodejs'// 'nodejs' | 'edge'
  • 'nodejs' (default)
  • 'edge'

preferredRegion

layout.tsx | page.tsx | route.ts
exportconstpreferredRegion='auto'// 'auto' | 'global' | 'home' | ['iad1', 'sfo1']

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

Good to know:

  • If apreferredRegion is not specified, it will inherit the option of the nearest parent layout.
  • The root layout defaults toall 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 usemaxDuration from the Next.js build output to add specific execution limits.

Note: This setting requires Next.js13.4.10 or higher.

layout.tsx | page.tsx | route.ts
exportconstmaxDuration=5

Good to know:

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

generateStaticParams

ThegenerateStaticParams function can be used in combination withdynamic 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 theAPI reference for more details.

Version History

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

Was this helpful?

supported.

[8]ページ先頭

©2009-2025 Movatter.jp