umi 配置路由如何配置父路由的默认子路由?

想要在访问/tab的时候默认展示 /tab/home
使用了重定向 但是重定向后 路径是对的但是页面是空的,
重定向到和/tab 平级的路由没有问题,重定向到子路由就不行, 这个该如何配置?

  {
    path: '/tab',
    component: '@/layouts/tabbar',
    routes: [
      { exact: true, title: '首页', path: '/tab/home', component: '@/pages/home' },
      { exact: true, title: '我的', path: '/tab/mine', component: '@/pages/mine' },
    ],
  }
阅读 11.3k
4 个回答
新手上路,请多包涵

配置子路由时这样子写
{pathname === "/tab" ? <Home/> : props.children}

新手上路,请多包涵

如何解决的呀?

我发现这样可以:

{
  path: '/tab',
  component: '@/layouts/tabbar',
  routes: [
    { exact: true, title: '首页', path: '/tab/home', component: '@/pages/home' },
    { exact: true, title: '我的', path: '/tab/mine', component: '@/pages/mine' },
    { redirect:'/tab/home'}
  ],
}

就是不知道这种写法对不对

用我的方法

{
    path: '/tab',
    component: '@/layouts/tabbar',
    routes: [
      { path:'/tab',redirect:'/tab/home'},
      { exact: true, title: '首页', path: '/tab/home', component: '@/pages/home' },
      { exact: true, title: '我的', path: '/tab/mine', component: '@/pages/mine' },
      { path:'*', redirect:'/notFound(这个路由需要自己去定义)'}
    ],
}

特意注册账号来回答您的问题~~

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题