Vue提示warn:”[vue-router] Named Route ‘home’ has a default child route…”

13,002次阅读
7条评论

共计 529 个字符,预计需要花费 2 分钟才能阅读完成。

问题描述

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

export default new Router({
  routes: [
    {
      path: '/',
      name: 'home',
      component: Home,
      children:[
        {
          path:'/',
          name: 'console',
          component: Console,
        }
      ]
    }
  ]
})
如果写法是如上的写法,就会报出如下警告:
[vue-router] Named Route ‘home’ has a default child route. When navigating to this named route (:to=”{name: ‘home'”), 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 属性即可。

正文完
使用官方微信小程序体验更多功能
post-qrcode
 47
憧憬Licoy
版权声明:本站原创文章,由 憧憬Licoy 2017-10-13发表,共计529字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(7条评论)
Keep 评论达人 LV.1
2021-01-03 11:51:44 回复

如果做动态路由刚刚有需要父级使用这个name咋搞

 Macintosh  Chrome  中国湖北省武汉市鹏博士
flowerxuegao 评论达人 LV.1
2019-11-07 08:49:34 回复

解决了一个警告,感谢作者

 Windows  Chrome  中国山西省太原市联通
超宝宝 评论达人 LV.1
2018-03-19 10:45:01 回复

刚好遇到这个问题,刚好解决啦,谢谢

 Windows  Chrome  中国四川省成都市电信
快乐网讯 评论达人 LV.1
2017-10-23 11:11:05 回复

文章不错支持一下吧

 Windows  Chrome  中国广东省佛山市电信