Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change query parameters in vue without reloading component

How do i change the query Parameters without reloading component in Vue with Vue-Router. But pushing new query always reload the component making my api request to rerun

this.router.replace({query: {name: 'John'} })

like image 811
Sunny Avatar asked Nov 14 '25 14:11

Sunny


1 Answers

This one works well in Nuxt, so I guess it's totally fine in Vue (even 3) too.

<button @click="$router.replace({ path: $route.path, query: { plan: 'private' } })">test</button>

It will push the same path you're currently on, but will change the query param in it.

Taken from the official docs: https://router.vuejs.org/guide/essentials/navigation.html

like image 85
kissu Avatar answered Nov 17 '25 08:11

kissu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!