Named Route index has a default child route. When navigating to this named route to name index

⚠警告 

[vue-router] Named Route 'index' has a default child route. When navigating to this named route (:to="{name: 'index'"), the default child route will not be rendered. Remove the name from this route and use the name of the default child route for named links instead

在Vue的项目中使用了Vue-Router,当某个路由有子级路由时,如下写法 

export default new Router({
  routes: [
    {
      path: '/',
      name: 'home',
      component: ()=>import('@/components/pages/home'),
      children:[
        {
          path:'list',
          name: 'list',
          component: ()=>import('@/components/pages/menu/list'),
        }
      ]
    }
  ]
})

如果写法是如上的写法,就会报出如下警告:

vue-router.esm.js?fe87:16 [vue-router] Named Route 'index' has a default child route. When navigating to this named route (:to="{name: 'index'"), the default child route will not be rendered. Remove the name from this route and use the name of the default child route for named links instead.

解决办法

因为当某个路由有子级路由的时候,这时候父级路由需要一个默认的路由,所以父级路由不能定义name属性,SO解决办法是:即去除父级的name属性即可

posted @ 2023-06-18 16:41  JackieDYH  阅读(192)  评论(0编辑  收藏  举报  来源