Next.js Discord

Discord Forum

How to conditionally skip rendering a page with App Router and generateStaticParams

Large garden bumble bee posted this in #help-forum
Open in Discord
Large garden bumble beeOP

As per the title, how do I conditionally skip out of statically rendering a page based on a build-time environment variable in NextJS? See the screenshot attached for a rough example of what I'm trying to accomplish.

I've tried it with dynamicParams: false and returning an empty array, but that just throws an exception on build-time: Page is missing "generateStaticParams()" so it cannot be used with "output: export" config.

I understood previously this could've been achieved with using exportPathMap ( but that's been deprecated. Is there a new/better way of doing this or should I still give it a shot? Thanks for the assistance!

0 Replies