#Optional Catch-all Segments and generateStaticParams

5 messages · Page 1 of 1 (latest)

hasty heart
#

Given this route 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!

west walrusBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

zenith perch
hasty heart
#

got it!

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/b

confirmed this by running npm run build and inspecting the build folder: .next/server/app

found shop.html, a.html and b.html files

thanks for the help <@&1159364112724262982> !

west walrusBOT
#
✅ Success!

This question has been marked as answered! If you have any other questions, feel free to create another post

Jump to answer

[Click here](#1244870309446680690 message)