Prerender known content paths
A blog, documentation site, or catalog has a known collection of slugs or IDs at build time.
Next.js 16+ · Function
generateStaticParams supplies dynamic-segment values that Next.js uses to prerender routes during the build. It can target all known paths or only a selected subset.
Export generateStaticParams from a dynamic route to provide the parameter values Next.js should prerender. It returns one object per generated pathname, with property names matching the route's dynamic segments; the function can be async when values come from a data source.
export async function generateStaticParams(): Promise<Array<Record<string, string | string[]>>>An array of objects; each object contains values for the dynamic segments of one route to generate.
export async function generateStaticParams() {
const posts = await fetch('https://example.com/api/posts').then((res) => res.json())
return posts.map((post: { slug: string }) => ({ slug: post.slug }))
}
export default async function Page({ params }: PageProps<'/blog/[slug]'>) {
const { slug } = await params
return <h1>{slug}</h1>
}Fetches known posts during the build and returns one parameter object per blog route.
A blog, documentation site, or catalog has a known collection of slugs or IDs at build time.
Only popular or editorially selected dynamic paths should be generated initially.
A dynamic route handler should expose static responses for known parameter combinations.
It supplies parameter objects for dynamic segments so Next.js can statically generate matching routes at build time rather than on demand. It is supported by pages, layouts, and route handlers.
Follow-up: How would you generate only selected routes? Return an array containing only the parameter objects for those routes.
Return an array in which each object represents one route's populated dynamic segments. For a [slug] segment, each object needs a slug property containing the value used in that pathname.
Follow-up: What must be true for a nested route with multiple dynamic segments? The generated parameter data must populate the dynamic segments required for each generated route.
It runs before the corresponding layouts or pages are generated during next build. It is not called again during ISR, so regenerated output does not cause a fresh parameter discovery pass.
Follow-up: What happens with Cache Components and an empty array? The build fails because at least one parameter is required to validate a non-empty static shell.
dynamic route segmentsgenerateMetadataPageLayoutRoute HandlersdynamicParams