Headless CMS content
Dynamic Pages Router pages use identifiers from a CMS to determine which URLs to prerender.
Next.js 16+ · Type Alias
getStaticPaths defines dynamic Pages Router paths for static prerendering. It is deprecated for App Router usage, where generateStaticParams is the replacement.
getStaticPaths is a Pages Router API for declaring dynamic URLs that Next.js should prerender. It returns route parameter objects and a fallback policy, and must be paired with getStaticProps; App Router projects use generateStaticParams instead.
export async function getStaticPaths() {
return {
paths: [{ params: { id: '1' } }],
fallback: false,
}
}| Name | Type | Description |
|---|---|---|
| | No positional parameters; the exported function reads external data or application state to construct its result. |
An object containing the required paths array and fallback setting; each path can include a params object matching the dynamic route segments.
paths property lists the URLs Next.js will generate ahead of requests.getStaticProps.fallback: false, an unlisted dynamic path produces a 404.import type { GetStaticPaths } from 'next'
export const getStaticPaths: GetStaticPaths = async () => {
const posts = await fetch('https://api.vercel.app/blog').then((res) => res.json())
return {
paths: posts.map((post: { id: number }) => ({
params: { id: String(post.id) },
})),
fallback: 'blocking',
}
}
This Pages Router example derives dynamic route parameters from external data and enables on-demand generation for paths not produced at build time.
Dynamic Pages Router pages use identifiers from a CMS to determine which URLs to prerender.
Database records provide the IDs or slugs for generated dynamic pages.
Markdown or other local files determine the available dynamic URLs.
A site wants unknown dynamic pages generated only when requested.
getStaticPaths do?It exports the set of dynamic route paths that should be statically prerendered. The return value includes paths and a fallback setting, and the API is used with getStaticProps.
Follow-up: How would you support paths that are not known at build time? Return an appropriate fallback mode, such as 'blocking', so the requested page can be generated on demand.
paths entries have?Each item in paths supplies route parameters under params. Those parameter names must correspond to the dynamic segments in the page filename, such as id for pages/posts/[id].js.
Follow-up: How do catch-all routes differ? Their matching parameter value is an array representing the route segments rather than a single scalar value.
getStaticPaths run?In production, the function runs during the build and the returned paths are rendered to HTML then. In development, it runs on every request, which supports a faster feedback loop.
Follow-up: What replaces this API in the App Router? generateStaticParams serves the corresponding role for routes under app.
getStaticPropsgenerateStaticParamsfallbackDynamic Routes