Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can vue-router push({name:"question"}) with hash?

eg: the changed route is https://stackoverflow.com/question#hello

router.push(location, onComplete?, onAbort?) name is required in localtion

like image 280
vigdxx Avatar asked Sep 10 '18 09:09

vigdxx


People also ask

What is hash mode in VUE router?

The default mode for vue-router is hash mode - it uses the URL hash to simulate a full URL so that the page won't be reloaded when the URL changes. To get rid of the hash, we can use the router's history mode, which leverages the history.

What does router Push do in Vue?

To navigate to a different URL, use router.push . This method pushes a new entry into the history stack, so when the user clicks the browser back button they will be taken to the previous URL.

How do you remove hash from Vue?

Setting the history option to the result of the createWebHistory() function from vue-router switches the router from hash history mode to HTML5 history mode. This removes the hash from the URLs.


2 Answers

Vue Router allows you to completely customize the scroll behavior on route navigation. Vue scroll behavior is a wide topic, so you can dive into docs

For your example I think you need hash prop, with scroll behavior:

Router.push({ name: routeName, hash: '#toHash' })
like image 108
Nika Kurashvili Avatar answered Nov 13 '22 18:11

Nika Kurashvili


router.push({ name: 'question', hash: '#hello' }) can work

like image 2
vigdxx Avatar answered Nov 13 '22 17:11

vigdxx