VUE中影藏hash#
在index.js中直接将原有的
new Router({
routes: []
}
加入mode: ‘history’
new Router({
mode: 'history',
routes: []
})
这样就可以实现无hash加载
在routes列表的最下面加入通配符还可以将所有错误(无法匹配)的route统一跳转到一个页面,如
new Router({
mode: 'history',
routes: [
{
path: '/login',
name: 'login',
component: (resolve) => require(['xxx'], resolve),
},
...
{
path: '/*',
name: '*',
redirect:{name:"login"}
}
]
})
这样用户会在输入router未定义的其他页面中跳转到一个已经设置好的页面