Skip to main content

What is `generateStaticParams`?

generateStaticParams in Next.js (App Router) is a server function that tells Next.js which values of a dynamic route's parameters need to be generated in advance at build time.

Simply put:

It turns a dynamic route into a set of static pages (SSG).


Why generateStaticParams is needed

Without it, a dynamic route:

txt
app/blog/[slug]/page.tsx
  • does not know which slug values exist.

generateStaticParams:

  • returns a list of slug values
  • Next.js generates HTML for each value
  • pages are served from the CDN as regular static files

Basic example

ts
export async function generateStaticParams() { const posts = await getPosts() return posts.map(post => ({ slug: post.slug, })) }
ts
export default function Page({ params }) { return <Article slug={params.slug} /> }

Result: /blog/post-1, /blog/post-2, /blog/post-3 - static pages


Where it is used

blogs documentation catalogs SEO pages roadmaps


Connection with rendering

ScenarioBehavior
generateStaticParams existsSSG
+ revalidateISR
No generateStaticParamsSSR (on request)

Important nuances

1. Runs only on the server

  • database access
  • API access
  • secrets are safe

2. Works only with the App Router

it doesn't exist in pages/ only app/


3. Can be combined with ISR

ts
export const revalidate = 60
  • pages update without a rebuild

4. Doesn't have to cover everything

You can:

  • generate popular pages
  • render the rest on request

Frequent mistakes

confusing it with getStaticPaths (Pages Router) returning the wrong object shape expecting client-side access


Short interview answer

generateStaticParams is an App Router function in Next.js that defines the list of dynamic route parameters for static page generation at build time.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.