Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue.js - How to remove hashbang #! from url?

How to remove hashbang #! from url?

I found option to disable hashbang in vue router documentation ( http://vuejs.github.io/vue-router/en/options.html ) but this option removes #! and just put #

Is there any way to have clean url?

Example:

NOT: #!/home

BUT: /home

Thanks!

like image 656
DokiCRO Avatar asked Jan 06 '16 00:01

DokiCRO


People also ask

How do I clear my vue router?

"There is no way to clear the session history or to disable the back/forward navigation from unprivileged code. The closest available solution is the location. replace() method, which replaces the current item of the session history with the provided URL."

What is history 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 is VUEX in VUE JS?

Vuex is a state management pattern + library for Vue. js applications. It serves as a centralized store for all the components in an application, with rules ensuring that the state can only be mutated in a predictable fashion.


2 Answers

You'd actually just want to set mode to 'history'.

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

Make sure your server is configured to handle these links, though. https://router.vuejs.org/guide/essentials/history-mode.html

like image 86
Bill Criswell Avatar answered Oct 13 '22 01:10

Bill Criswell


For vue.js 2 use the following:

const router = new VueRouter({  mode: 'history' }) 
like image 21
Israel Morales Avatar answered Oct 13 '22 02:10

Israel Morales