当用户导航到根路径时,我想默认到特定页面,即当使用到myapp.com时,我想将它们重定向到myapp.com/defaultpage
我当前的代码是
index.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时,我才能进入正确的页面。
有任何想法吗?


您可以使用1行代码(即添加)来完成此操作
router.replace("myPath");。完整代码: