How to remove hashbang from url?

后端 未结 11 618
生来不讨喜
生来不讨喜 2020-11-30 17:04

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 )

11条回答
  •  萌比男神i
    2020-11-30 17:49

    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.pushState API to achieve URL navigation without a page reload:

    import {routes} from './routes'; //import the routes from routes.js    
    
    const router = new VueRouter({
        routes,
        mode: "history",
    });
    
    new Vue({
        el: '#app',
        router,
        render: h => h(App)
    });
    

    routes.js

    import ComponentName from './ComponentName';
    
    export const routes = [
       {
          path:'/your-path'
          component:ComponentName
       }
    ]
    

    Reference

提交回复
热议问题