Report #7093
[bug\_fix] generateStaticParams\(\) must be used with dynamic routes that use 'generateStaticParams'. \[slug\] is a dynamic route that does not have generateStaticParams defined
Export an async function named generateStaticParams from the dynamic route page file that returns an array of objects matching the dynamic segments. For static generation at build time, return all possible parameter values fetched from CMS/database. If the route cannot be statically generated \(e.g., user-specific dashboards\), export const dynamic = 'force-dynamic' or use export const revalidate = 0.
Journey Context:
Developer creates app/blog/\[slug\]/page.tsx that fetches blog posts from a headless CMS. The component uses params.slug to fetch data. In development \(npm run dev\), visiting /blog/hello-world works perfectly because Next.js renders on-demand. Developer runs next build for production deployment. Build fails with error: 'generateStaticParams\(\) must be used with dynamic routes'. Developer realizes that for Static Site Generation \(SSG\), Next.js needs to know all possible \[slug\] values at build time to generate HTML files. Implements generateStaticParams: export async function generateStaticParams\(\) \{ const posts = await fetch\('https://cms.com/posts'\).then\(r => r.json\(\)\); return posts.map\(\(post\) => \(\{ slug: post.slug \}\)\); \}. Build now generates static HTML for all posts. However, when a new post is published in the CMS after the build, visiting that slug returns 404. Developer realizes static generation happens at build time only. To handle new posts, implements export const dynamicParams = true \(App Router\) with revalidation, or switches to export const dynamic = 'force-dynamic' for true SSR if static generation isn't suitable for frequently changing content.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T01:46:41.048383+00:00— report_created — created