Next.js Discord

Discord Forum

Static Render First Few Page

Unanswered
Green-tailed Towhee posted this in #help-forum
Open in Discord
Green-tailed TowheeOP
Hi everyone , I got a quick question , [I am new to nextjs14 ] .
I am trying to build a e commerce project and I want to run the first few /products/:id.... [1 to 50 ] statically and if the user requests for the 51the product or the product page is not statically generated at build , I want to dynamically create , How can I achieve this thank you 🙂

7 Replies

American Crow
You return the slugs (segments) you want to be statically generated from generateStaticParams() so in your case 1 , 2 , 3 , 4 , ... 50

Everything else NOT returned from gernateStaticParams will be rendered on demand at runtime (request time)
https://nextjs.org/docs/app/api-reference/functions/generate-static-params
@Clown https://nextjs.org/docs/app/building-your-application/routing/dynamic-routes#generating-static-params
Green-tailed TowheeOP
Thank you for responding .can i use server action instead of fetch ?