Static Render First Few Page
Unanswered
Green-tailed Towhee posted this in #help-forum
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 🙂
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
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
generateStaticParams() so in your case 1 , 2 , 3 , 4 , ... 50Everything 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
Here you go. You need to put this in your dynamic route page.
Obviously you'll need to change the stuff as needed
@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 ?
@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
Green-tailed TowheeOP
Thank u for replying , I get a loop of fetch request in stattic generated page , got any idea why that happens