dynamic (route segment config)
Controls whether a route is statically or dynamically rendered.
Syntax
export const dynamic = 'auto' | 'force-dynamic' | 'error' | 'force-static' Returns
string — Rendering strategy for the segment.
Examples
// Always render at request time
export const dynamic = 'force-dynamic'
export default async function Page() {
const data = await fetch('https://api.example.com/live', {
cache: 'no-store',
}).then((r) => r.json())
return <Live data={data} />
}
// Force fully static; error if dynamic APIs are used
export const dynamic = 'force-static'
export default function Page() {
return <p>Static content</p>
}
Notes
`auto` (default) lets Next choose based on the APIs used.
`force-dynamic` opts out of static rendering and caching (like
`cache: 'no-store'`). `force-static` forces static rendering,
returning empty cookies/headers. `error` makes any dynamic usage a
build error. Exported from `layout.js`/`page.js`/`route.js`.