EmielV
EmielV

Reputation: 207

How to remove the hashtag in the url with vue router?

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/#/

Upvotes: 1

Views: 2171

Answers (1)

Humayon Zafar
Humayon Zafar

Reputation: 1141

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

Upvotes: 5

Related Questions