Next.js Discord

Discord Forum

Generating known searchParams routes at build time

Answered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
Hey folks! I was wondering if there is a way to generate known searchParams routes at build time in the same way as generateStaticParams works but adding the searchParams values on top of the pathname.

So for example if I have two routes "/tshirt?color=blue" and "/tshirt?color=red" that get pushed depending if the user clicks on the red or blue button.

How can I make my app not fetch the route at request time when I click on the blue button or the red button ?

I tried router.prefetch but it messes up with the intro animation for some reason.
Answered by B33fb0n3
The short answer: you can’t.
The long answer (my recommendation): use suspense around it. Then your routes stays static (if static) and only the part that needs these searchparams is dynamic @Sun bear
View full answer

9 Replies

The short answer: you can’t.
The long answer (my recommendation): use suspense around it. Then your routes stays static (if static) and only the part that needs these searchparams is dynamic @Sun bear
Answer
thats what i thought, but id think to mention it because it isn't default enabled
Sun bearOP
Oh okay I can understand the hype around PPR then. Hopefully it becomes stable soon! Thanks
perfect 👍