Next.js Discord

Discord Forum

Can route with dynamic segment be generated/rendered as static in App Router?

Unanswered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
I have a route with dynamic segment, let's say
/blog/[slug] where slug is unknown at build time. When I build the project, it says "λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)". Is there any way to generate/render it as static HTML?
If I try to do same in pages folder, it is generated/rendered as static. Why so?

15 Replies

Yes, using generateStaticParams
or 'force-static'
@aardani or 'force-static'
Sun bearOP
Can you give reproducable example? Also I'm using output:'export' in next config
oh ure using output:"export"
@aardani oh ure using output:"export"
Sun bearOP
Yeah
I have other routes dynamic routes but I know their values at buildtime, but i'm not able to figure out how to handle if I don't know values at build time
since everything has to be known at build time
Sun bearOP
Not possible if we try to use dynamicParams=true and try using some dummy value at build time?
no
the reason output export exist is well, for truly statically generated pages
like static websites and SPAs
maybe you could opt-in to client side rendering instead?
Im really sorry i thought you meant without output:"export"