vue router 优先级

请问下我如何才能直接访问/render2这个路由呢?

const routes = [{
  path: '/',
  redirect: '/index'
}, {
  path: '/index',
  component: Index,
  meta: { keepAlive: true },
  children: [{
    path: '/preview',
    component: PreView,
    children: [{
      path: '/render2',
      component: render2
    }]
  }]
}, {
  path: '/render2',
  component: render2
}]

由于配置了

`children: [{

  path: '/render2',
  component: render2
}]`

每次都访问到/preview/render2去了

如何才能既能访问/preview/render2
又能直接访问/render2呢?

阅读 4.8k
3 个回答
children: [{
      path: '/render2',
      component: render2
    }]

改为

children: [{
      path: 'render2',
      component: render2
    }]

给路由加名字:

{
  path: '/render2',
  name: 'Render2',
  component: render2
}
router.push({ name: 'Render2' })

子路径都不用带'/',你改成这样试试

children: [{
    path: 'preview',
    component: PreView,
    children: [{
      path: 'render2',
      component: render2
    }]
  }]
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏