Skip to main content
generateStaticParams can be used with dynamic route segments to statically generate routes at build time instead of on-demand at request time. It can be exported from:
app/blog/[slug]/page.tsx

Parameters

object
When multiple dynamic segments in a route each export generateStaticParams, the child function receives the params object generated by the parent. This allows child segments to generate their own params based on parent values.

Returns

An array of objects where each object represents the populated dynamic segments of a single route.
  • Each property key is the segment name.
  • Each property value is the string value (or array of strings for catch-all segments) to fill in.

Good to know

  • Use dynamicParams to control what happens when a dynamic segment not covered by generateStaticParams is visited.
  • Return an empty array (or use export const dynamic = 'force-static') to render all paths at runtime (ISR).
  • During next dev, generateStaticParams is called when you navigate to a route.
  • During next build, it runs before the corresponding Layouts and Pages are generated.
  • During revalidation (ISR), generateStaticParams is not called again.
  • generateStaticParams replaces getStaticPaths from the Pages Router.
  • fetch requests in generateStaticParams are automatically memoized across all generate-prefixed functions, Layouts, Pages, and Server Components.

Examples

Single dynamic segment

app/product/[id]/page.tsx

Multiple dynamic segments

app/products/[category]/[product]/page.tsx

Catch-all segment

app/product/[...slug]/page.tsx

All paths at build time

app/blog/[slug]/page.tsx

Subset of paths, rest at runtime

app/blog/[slug]/page.tsx

Disabling unspecified paths (404)

app/blog/[slug]/page.tsx

Multiple dynamic segments (top-down)

Generate parent segment params first, then use them in child generateStaticParams:
app/products/[category]/layout.tsx
app/products/[category]/[product]/page.tsx

Version history