Vue Router去掉url中默认的#

hash模式url

clipboard.png

vue-router默认hash模式——使用URL的hash来模拟一个完整的URL,因而当URL改变时,页面不会从新加载。
若是不想要这种默认的hash模式,能够用路由的history模式,这种模式充分的利用history.pushState API来完成URL跳转而无需从新加载页面。vue

index.js
Vue.use(Router)

export default new Router({
  mode: 'history',
  routes: [
    {
        path:"/xxx",
        name:"xxx",
        component: Xxx,
    }
]
})

clipboard.png

history模式

修改以后url就变成了正常的urlvue-router

clipboard.png

相关文章
相关标签/搜索