当用户导航到根路径时,我想默认到特定页面 即当使用转到 myapp.com 我想将它们重定向到 myapp.com/defaultpage
我当前的代码是
索引.js
import Full from '../containers/Full'
import DefaultView from '../views/DefaultView'
export default new Router({
mode: 'history',
linkActiveClass: 'open active',
scrollBehavior: () => ({ y: 0 }),
routes: [
{
path: '/',
redirect: '/defaultview',
name: 'home',
component: Full,
children: [
{
path: '/defaultview',
name: 'defaultview',
component: DefaultView
},
{
path: '*',
component: NotFoundComponent
}
}
]})
当用户访问 myapp.com 时,我收到“404 页面未找到”- 即 NotFoundComponent。只有当我输入 myapp.com/defaultview 时,我才能到达正确的页面。
有什么想法吗?
最佳答案
试试这段代码:
routes: [
{
path: '/',
redirect: '/defaultview'
},
{
path: '/defaultview',
name: 'defaultview',
component: DefaultView
},
{
path: '*',
component: NotFoundComponent
}
]
关于vue.js - vue-router 重定向到默认路径问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44060414/