Optional Catch-all Segments and generateStaticParams
Answered
Russian Blue posted this in #help-forum
Russian BlueOP
Given this route
How to statically generate the root page (/shop in the example above?
I understand for non-optional catch-all segments
—
export function generateStaticParams() {
return [{ slug: ["a"] }, { slug: [b] }];
}
// generates
// /shop/a
// /shop/b
I’m wondering if possible to do this for the ‘root’ page when using optional catch-all segments
Thanks for the help!
pages/shop/[[...slug]].js,How to statically generate the root page (/shop in the example above?
I understand for non-optional catch-all segments
—
pages/shop/[...slug].js — we can statically generate segments like so:export function generateStaticParams() {
return [{ slug: ["a"] }, { slug: [b] }];
}
// generates
// /shop/a
// /shop/b
I’m wondering if possible to do this for the ‘root’ page when using optional catch-all segments
Thanks for the help!
2 Replies
Russian BlueOP
got it!
an empty array does generate the the root page. in my 'shop' example above,
confirmed this by running
found shop.html, a.html and b.html files
thanks for the help &1159364112724262982 !
an empty array does generate the the root page. in my 'shop' example above,
export function generateStaticParams() {
return [{ slug: [] }, { slug: ["a"] }, { slug: ["b"] }];
}// generates
// /shop
// /shop/a
// /shop/bconfirmed this by running
npm run build and inspecting the build folder: .next/server/appfound shop.html, a.html and b.html files
thanks for the help &1159364112724262982 !