All my attempts to remove the query string fails:
// Initial state
this.$router.replace({
    name: 'routeName',
    query: {
        param: 123
    }
});
// Errors
this.$router.replace({ query: {}});
this.$router.replace({ query: undefined });
this.$router.replace({ query: null });
How to remove query without any errors?
I'm using Vue Router v3.1.5
Vue 3
This worked for me:
import { useRoute, useRouter } from 'vue-router'
// put this inside your setup() function:
const route = useRoute()
const router = useRouter()
if (route.query.username = 'test') {
  // do stuff...
  
  // clear the query
  router.replace({ query: {} })      
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With