Search code examples
vue.jsvue-router

How to drop a query in a url?


I have the following url: http://0.0.0.0:3000/book/all?my_query.

How can I drop the all?my_query and leave just book/?

I tried to do something like this:

if (this.$route.params.item === 'all') { 
  this.$router.replace ('/') 
}

But that approach just returns me to the main page.


Solution

  • To remove all params:

    this.$router.replace({'query': null});
    

    To add my_query param:

    this.$router.replace({'query': {'my_query': 1}});