path: '/',
name: 'layout', // 一级路由设置了name属性
component: () => import('@/views/layout'),
children: [
{
path: '', // 子路由为默认路由
name: 'home',
component: () => import('@/views/home')
},
]
控制台警告
vue-router.esm.js?8c4f:16 [vue-router] Named Route 'layout' has a default child route. When navigating to this named route (:to="{name: 'layout'"), 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.
原因分析:
根据报错得知,名为‘layout’的路由有一个默认的子路由,要从这个路由中删除名称,使用默认子路由来代替
解决方案:
将layout的name属性删除