i am building a next js application and for my site, query params are important and they need to be forwarded between pages back and forth. Below are the scenarios –
user landed on my home page with certain query params ( lets say utm params ). i want these utm params to be there with the url all through the user journey in the same tab.
also query params will be added in between like the user selected date and other data like campaign related params. these also need to stay in the url throughtout the complete user journey
Basically, when routing from in the serverside with redirect function from ‘next/navigation’ or from the router.push happening in the client components, i want the query params to be forwarded.
Also, i have certain different endpoints ( backend service endpoints ), which require the query params to be passed and these get triggered on the server side ( in react server components as well as in react components ). for these endpoints also,i want to fetch the query params and forward them down.
Please suggest me some standard approaches for the above use case to forward the query params. Thanks.
over client components, i used the urlsearchparams and it is working fine. I want this constructed well in the server side components in server components and in server actions which will be standard approach.
ravikiran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.