NNext.jsSource ↗
The prefetch route segment config controls how a segment is prefetched during client-side navigation. By default, the framework manages the strategy based on the app's partialPrefetching setting. To override p …truncated by Smolify import.

The prefetch route segment config controls how a segment is prefetched during client-side navigation. By default, the framework manages the strategy based on the app's partialPrefetching setting. To override per segment, set this export to one of the values below.

Good to know:

  • The prefetch export only works when cacheComponents is enabled.
  • prefetch cannot be used when the segment is a Client Component.
  • The meaningful values to set are 'allow-runtime', 'partial', and 'force-disabled'. 'auto' is the default and is equivalent to omitting the export; don't write prefetch = 'auto' explicitly.
export const prefetch = 'allow-runtime'

export default function Page() {
  return <div>...</div>
}
export const prefetch = 'allow-runtime'

export default function Page() {
  return <div>...</div>
}

Options

'allow-runtime'

Allows Next.js to prefetch this segment at runtime. Setting this option lets the server render a fresh response that resolves per-link runtime data: params, searchParams, and the full URL. Cookies and headers don't need 'allow-runtime'. The framework already includes them in the App Shell when the route reads them. Use this for personalized content when the latency and cost of runtime prefetching are appropriate for the segment.

Good to know: When Next.js runtime-prefetches a segment, all downstream segments are included in the same runtime prefetch request. Segments deeper in the tree that are configured with 'force-disabled' will still be prefetched as part of the runtime response.

export const prefetch = 'allow-runtime'

'partial'

Opts the segment into Partial Prefetching without enabling the global partialPrefetching flag. A <Link> pointing at a segment with prefetch = 'partial' loads the per-route App Shell instead of the legacy full prefetch. Set this on the destination, not the link.

Use this for incremental adoption when you can't enable partialPrefetching for the entire app at once. Once every route in scope has prefetch = 'partial', enable the global flag and remove the per-route exports.

export const prefetch = 'partial'

'force-disabled'

Never prefetch this segment. The client will not request segment data ahead of navigation. Use this for segments where prefetching would be wasteful, for example pages behind authentication that are rarely visited.

Good to know: 'force-disabled' does not prevent Next.js from prefetching metadata about the route. However, the actual segment data for this segment and all deeper segments will be omitted from prefetching.

A prefetch starts with a <Link> that expresses intent (should this destination be prefetched, and how eagerly), and ends at a segment that sets a cost ceiling (how much work is it OK to do ahead of time, for any link that points here).

A destination can't know which links target it, so the segment config caps what any <Link prefetch={true}> pulls:

<Link prefetch={false}> skips prefetching at the link level regardless of how the destination is configured.

Good to know: A prefetch may be served from a CDN cache, reuse a cached App Shell, or run a fresh server render. Wider prefetches lean toward fresh server work and cost more server CPU per page view.

TypeScript

type Prefetch = 'auto' | 'allow-runtime' | 'partial' | 'force-disabled'

export const prefetch: Prefetch = 'allow-runtime'

Version History

Version Changes
v16.x.x prefetch export introduced (Cache Components only)

Source: docs/01-app/03-api-reference/03-file-conventions/02-route-segment-config/prefetch.mdx

Generated by smolify with deterministic-repository-import-v1 · 1 source file
prefetch — Next.js · Smolify