How to correctly make route be statically generated (SSG)?
Answered
Nile Crocodile posted this in #help-forum
Nile CrocodileOP
I have a route
When getting the page I do it by the id of the document.
But when building my app it doesnt list all of the potential routes. It just says its SSG without listing the possible routes.
In my
But that doesn't seem to do it? I can provide more details if needed.
/cars/[id]/[name]/page.tsx
and in my CMS document I have route
which is /cars/<doc.id>/<doc.name>
.When getting the page I do it by the id of the document.
But when building my app it doesnt list all of the potential routes. It just says its SSG without listing the possible routes.
In my
generateStaticParams
I have:const params = cars.docs.map(({ route }) => ({
slug: route,
}));
But that doesn't seem to do it? I can provide more details if needed.
Answered by joulev
you have to return
{ id: string, name: string }[]
instead of { slug: string }[]
26 Replies
Nile CrocodileOP
And to add, I have a
[[...slug]]/page.tsx
route for pages which works fine for SSG I just cant get it to work for the /cars/[id]/[name]/page.tsx
route@Nile Crocodile I have a route `/cars/[id]/[name]/page.tsx` and in my CMS document I have `route` which is `/cars/<doc.id>/<doc.name>`.
When getting the page I do it by the id of the document.
But when building my app it doesnt list all of the potential routes. It just says its SSG without listing the possible routes.
In my `generateStaticParams` I have:
const params = cars.docs.map(({ route }) => ({
slug: route,
}));
But that doesn't seem to do it? I can provide more details if needed.
It just says its SSG without listing the possible routes.could you clarify this part? what does the build log say?
Nile CrocodileOP
Hi @joulev thanks for your response! The outlook is this
interesting... could you show the code for
/cars/[id]/[name]/page.tsx
? can redact the secret parts but i need to know the overall structure and the exports that the page file declaresNile CrocodileOP
Here you go
I think ive just found the issue - I'm returning an array instead of an object for params inside
generateStaticParams
- ignore thats wrong@Nile Crocodile Here you go
it looks okay to me... other than the draft mode. i dont know it tho bcause ive never used it – but try removing the draftMode call; would it work now?
also add
export const dynamicParams = false
https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamicparamshmm still the same
if you add
export const dynamic = "error"
to the page, does the build pass or fail? if it passes, then the page is definitely absolutely staticfrom the log, despite no slugs being printed i think it's still static already
oh yeah just checking, the
params
returned by generateStaticParams
– this one is not an empty array right? just sanity checkNile CrocodileOP
is it possible to make
/[id]/[name]/page.tsx
static without a page.tsx
inside /[id]/
yes it is, in this case it seems it's static already
OH WAIT i think i know why
Nile CrocodileOP
ok - its changed from SSG dot to Static dot
you have to return
{ id: string, name: string }[]
instead of { slug: string }[]
Answer
inside
generateStaticParams
the type of the param is
{ id: string, name: string }
Nile CrocodileOP
ahhh okay that actually makes sense lol
Thanks so much @joulev !!
yea sorry it took a few guesses, thats quite a hidden bug
Nile CrocodileOP
no dont be sorry, I would never have seen it
well... enjoy your day, you're welcome
Nile CrocodileOP
You too!