设置vue-cli的默认路由
当我们创建vue-cli项目时,路径是http://localhost:9527/#/,但是这是有缺陷的首先#在很多环境中不允许使用或者使用时有严重的缺陷,其次从命名的角度来看也是不友好的。所以为了解决这个问题,vue提供了history-mode模式;来解决这个问题。
另一个问题是,浏览器默认访问的是http://localhost:9527这种连接,但是我们需要默认去登录页面,例如:http://localhost:9527/login,这时我们就用到了router的redirect属性;
let router = new Router({
mode: 'history',
routes: [
{
path: '/',
redirect: '/login' //重定向到登录页面
},
{
path: '/login',
name: 'Login',
component: Login
},
{
path: '/main',
name: 'main',
component: Main
}
]
})
还没有评论,来说两句吧...