4

Current url is

/search

New url should be

/search?foo=bar

I just want to update my query params being on the same route as a result of application of some filters on the page

My code:

this.$router.push({query: params})

There is a way to handle the "NavigationDuplicated" error using a catch block but that only supresses the error, the query parameters in the route are still not updated.

Related issue:

How to use router.push for same path, different query parameter in Vue.js

But this gives the path '/' but i need to remain on the same page

4
  • Although it doesn't solve your problem, a workaround would be to completely reload the page, or store the values in a state storage like vuex 🤔 Commented Jan 18, 2020 at 14:28
  • neither are feasible, reloading the entire page on a filter is just bad UX and storing the values would not make the url shareable to others.If someone opens the same url it should reapply those filters Commented Jan 18, 2020 at 14:33
  • It does, you write the query params to a vuex store, and read them from there instead from the queries. If the page is loaded, you check the queries and store them into the vuex storage. Commented Jan 18, 2020 at 14:38
  • @WajihSiddiqui ? You probably has error in your router file. Can you paste it? Commented Jan 21, 2020 at 16:23

2 Answers 2

0

You can add catch to workaround this error:

this.$router.push({query:params}).catch(() => {})
Sign up to request clarification or add additional context in comments.

1 Comment

what will this error handler do exactly, the task i wanted to achieve (pushing param into url) failed, can't add this statement in the catch again
0

You can use history.pushState(), it will modify the URL without pushing the router.

https://stackoverflow.com/a/71042001/19222560

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.