1

I have a Vue.js app that has a tagging component. I'd like to add a url components like https://thisdomain.com/some?tag_ids=3,7,11 where a user can add tag_ids by toggling the tags in the UI.

While this is working for maintaining the tag_ids in the app. I'd also like to have them render in the browser url so that if the url is shared, it looks the same. I am using vue-router and I'd like to add the tag_ids to the query string but not force a new route in the path. I have tried something like:

   this.$router.push({ path: '/', tag_ids: this.selectedTagIds })

and

   this.$router.replace({ path: '/', tag_ids: this.selectedTagIds })

But this is not working. Any idea how to manipulate the query params via this.$router?

1 Answer 1

2

You can use params:

//navigation
this.$router.push({ name: 'some', params: { tag_ids: this.selectedTagIds } })

//route
{ path: '/some', name: 'some', component: Some }

Or, you can use query like this:

this.$router.push({ path: '/some', query: { tag_ids: this.selectedTagIds } })
Sign up to request clarification or add additional context in comments.

1 Comment

Good one +!. I think query is what the OP seems to need.

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.