How do I get vue-router to modify the route without refreshing the page?

in the single-page application built by vuejs, I have the following special needs:

Click a button on the page to add a logo after the current url. For example, the original route is
http://127.0.0.1:3000/,
. After clicking the button, the route changes to
http://127.0.0.1:3000/?tab=2,
but the page cannot be refreshed.


:3000/
in the

routing history is to be replaced by
http://127.0.0.1:3000/?tab=2.

what should I do? No. Ask the great god to point out the train of thought.

Sep.08,2021

Hello, landlord! In fact, this depends on your usage scenario, and there may be other solutions. The visual function you want to achieve may be to control the selection of tab on the page through the parameters of the url address. Alternative options, storage, Vuex etc.


$router.replace ()


this.$router.replace ('? tab=2')


or refresh the page to use vue's: ide/components-dynamic-async.html-sharp%E5%9C%A8%E5%8A%A8%E6%80%81%E7%BB%84%E4%BB%B6%E4%B8%8A%E4%BD % BF%E7%94%A8-keep-alive "rel=" nofollow noreferrer "> keep-alive


Gee vue-router push won't refresh the page to the current page in the first place. You can add parameters and only modify url. < del > ~ < / del > ~


you can try that location.hash, will add a string that begins with-sharp after the current url, and will replace the current route


history.pushState ()

in the routing history.
Menu