Generating known searchParams routes at build time
Answered
Sun bear posted this in #help-forum
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.
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
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
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
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
@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 <@834134594302640139>
isn't that long answer with ppr or am i missunderstanding?
@riský isn't that long answer with ppr or am i missunderstanding?
basically it's ppr, yea
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
@Sun bear Oh okay I can understand the hype around PPR then. Hopefully it becomes stable soon! Thanks
yea ^^
Would you mark this message as solution?
https://nextjs-forum.com/post/1181180737236520990#message-1181194787559321633
Would you mark this message as solution?
https://nextjs-forum.com/post/1181180737236520990#message-1181194787559321633
perfect ðŸ‘