如果不做重定向,页面就会空,比如刚打开时 url 是 localhost:8080,我希望能重定向到 Index 组件,即 localhost:8080/index,现在我是给 index 组件加了个别名 alias '/' 解决,是否可以用程序方式解决?因为我看之前 vue 1 别人的代码有这样写:router.redirect({ '*': '/index'})现在 vue 2 是不行了吗?补充: 看了楼下的回复,本来觉得 replace 不错,但是 replace 有个问题,如果打开的是别的页面,也会被 replace 过去 ...
1 回答

动漫人物
TA贡献1815条经验 获得超10个赞
//routesvar router = new VueRouter({ mode: 'hash', routes: [ { path: '/index', component: require('./pages/index.vue') }, { path: "*", redirect: '/index' }, ] });
这样重定向
添加回答
举报
0/150
提交
取消