Return an Array in generateStaticParams
When you’re using the Catch-all Segments feature, you must return an array of params in generateStaticParams
, even though it should always contain a single entry.
And it kinda makes sense if you really think about it:
Route: pages/shop/[...slug].js
URL: /shop/a
Params: { slug: ['a'] }
URL: /shop/a/b/c
Params: { slug: ['a', 'b', 'c'] }
In this case, slug
is an array, as it might contain multiple URL segments. But when using generateStaticParams
, you are basically generating params for every single page.
And yet, instead of items.map((item) => ({ slug: item.slug }))
you’d go for items.map((item) => ({ slug: [item.slug] }))
, so it goes with the catch-all paradigm of “might be more than one”. Another case where things mix up too much. I guess better documentation might help.