If we come from an external source to our web page, we have utm parameters added in our url for quite some time(as in only in first page), then if we go to some other route, those parameters disappear. Now I want to retain those utm parameters for all the routes I have in my application. And I want some global level solution as in some kind of middleware or any event which we can trigger before history changes, we can have so that we need not to append parameters explicitly in each router.push(). If anyone has any idea please help.
Asked
Active
Viewed 914 times
1
-
If your application can use session, please try https://www.npmjs.com/package/next-session – JSN Dec 27 '21 at 06:09
-
Actually I dont want it for API routes, only for SPA routes. And I have tried _middleware but it is not supporting with latest next version – Muskan Rawal Dec 27 '21 at 06:18
-
Ok, may be you can use `localStorage` or `sessionStorage` directly in client side? – JSN Dec 27 '21 at 06:19
-
You may refer this for code https://programmingwithmosh.com/react/localstorage-react/ – JSN Dec 27 '21 at 06:21
-
The point is I want a sort of event which we can trigger before history changes and can change the route without reloading. – Muskan Rawal Dec 27 '21 at 06:26
-
I am not very clear about your requirement. I hope you can solve this by listening to history changes in React (https://stackoverflow.com/questions/41911309/how-to-listen-to-route-changes-in-react-router-v4) and adding relevant `localStorage/sessionStorage` code – JSN Dec 27 '21 at 06:39