Home > Software engineering >  How to remove the hashtag in the url with vue router?
How to remove the hashtag in the url with vue router?

Time:12-03

I read online that the hashtag in the url is caused by not using history in the vue router.

Currently, I am working on a big project and it would be a timewaste to start over and select history mode in the terminal.

That is why I would like to ask if it is possible to use switch to history mode while the vue project is already generated?

This is my url: http://localhost:8081/#/

CodePudding user response:

The default mode for Vue router is hash-mode. You don't need the install the whole app again, just update the mode to history mode in your app where you have defined the vue router as follow:

For router v3:

const router = new VueRouter({
  mode: 'history'
})

For router v4:

const router = VueRouter.createRouter({
  history: VueRouter.createWebHashHistory(),
})

For reference: https://next.router.vuejs.org/guide/#javascript

  • Related