Top-Down generateStaticParams
Hard · Rendering
When a route has several dynamic segments, each segment (layout or page) can export its own generateStaticParams. Next.js runs them top-down: the parent runs first, and the child's generateStaticParams({ params }) is called once for every params object the parent produced, receiving the parent params. The results are combined into the list of pages to prerender.
Write async buildStaticPaths(route, specs). route is a route like "/shop/[category]/[product]". specs maps each param name to a data spec; the starter's makeGenerateStaticParams(name, spec) turns a spec into a real async generateStaticParams. Every dynamic segment has a spec.
- Process the dynamic segments from left to right. Start with one empty params object. For each segment, call its function once per current params object (await fn({ params })), and merge each returned object into a copy of that params object. A parent whose child returns [] produces no pages.
- Build a URL for every final params object. Route groups like (shop) are removed. [name] becomes the value, [...name] the array joined with / (skip the params object if the array is empty), [[...name]] the joined array, or nothing at all when it is empty or missing.
- Return the unique URLs sorted with the default sort(). A URL with no segments is "/".