How to add a persitent query param #1999
-
I'm trying to add a param into the url so it would persist during navigation. The idea is that it's used on application start to initialize an app state and then is kept in the url. On state changing the param is updated. First I tried beforeEach with next argument:
It caused a "Infinite redirect in navigation guard" error. Then followed a piece of advise from SO:
it works as I needed - adds the persistent argument but it causes infinite recursion (undetectable, so the app just hangs on load) when I call router.push:
(I do it in my App.vue's created hook). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The navigation guard you propose should work (I tested it): router.beforeEach(to => {
if (!('persistent' in to.query)) {
return {
...to,
query: {
...to.query,
persistent: 'I am inevitable'
}
}
}
}) Since the return is conditional, it won't face the infinite redirect issue you see with |
Beta Was this translation helpful? Give feedback.
The navigation guard you propose should work (I tested it):
Since the return is conditional, it won't face the infinite redirect issue you see with
next()