!!!注意:
1.有children时, children对象的path 开头不能加 /
2. 有children时,父级一定要加上component
方法一:addRoute(obj)
const obj = {
path: '/parent',
name: 'home',
component: Home,
children: [
{
path: 'child',
component: () => import('@/views/user/privacy-policy')
}
]
}
this.$router.addRoute(obj)// 添加新路由,通过地址栏可以正常访问新路由了
this.$router.options.routes.push(obj) //push到options中,可随时拿到路由结构数据
方法二:addRoutes(arr)
const obj = {
path: '/yyx123',
component: Layout,
children: [{
path: 'index',
component: () => import('@/views/user/privacy-policy'),
meta: {
title: '认证'
}
}]
}
this.$router.addRoutes([obj])// 添加新路由,通过地址栏可以正常访问新路由了
this.$router.options.routes.push(obj)//push到options中,可随时拿到路由结构数据
版权声明:本文为weixin_44171757原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。