CodePark/ questions / Rendering strategies
START PRACTICINGPRACTICE
Frontend question · Next.js › Rendering strategies

What does generateStaticParams do, and how does dynamicParams affect it?

// app/blog/[slug]/page.tsx
export const dynamicParams = false;

export async function generateStaticParams() {
  const posts = await getPosts();
  return posts.map((post) => ({ slug: post.slug }));
}

export default async function Page({ params }: { params: Promise<{ slug: string }> }) {
  const { slug } = await params;
  return <Post slug={slug} />;
}

generateStaticParams returns the list of params to prerender at build time. dynamicParams decides what happens to params that are not in that list.

generateStaticParams runs at build time in a dynamic route, like app/blog/[slug]. Each entry it returns becomes a static page. It replaces getStaticPaths from the Pages Router.

dynamicParams controls params that were not returned:

  • true (the default): they render on demand the first time someone requests them.
  • false (export const dynamicParams = false): any other value returns a 404.

A common pattern: prerender only the most popular pages at build time, and let the rest render on first visit. This keeps builds fast for large sites.

  • generateStaticParams runs at build time and returns the params to prerender.
  • It replaces getStaticPaths from the Pages Router.
  • With dynamicParams = true (the default), other params render on demand.
  • With dynamicParams = false, other params return a 404.
  • Prerender only popular pages to keep builds short.