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:
app/blog/[slug]/page.tsx- does not know which
slugvalues exist.
generateStaticParams:
- returns a list of
slugvalues - Next.js generates HTML for each value
- pages are served from the CDN as regular static files
Basic example
export async function generateStaticParams() {
const posts = await getPosts()
return posts.map(post => ({
slug: post.slug,
}))
}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
| Scenario | Behavior |
|---|---|
generateStaticParams exists | SSG |
+ revalidate | ISR |
No generateStaticParams | SSR (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
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
generateStaticParamsis 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 readyA concise answer to help you respond confidently on this topic during an interview.