通过递归的思维来获取:包含affix: true键值对路由器的绝对路径(父路由和子路由)
2021/5/6 18:27:40
本文主要是介绍通过递归的思维来获取:包含affix: true键值对路由器的绝对路径(父路由和子路由),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1.路由代码---4个路由对象
var router = [ { path: '/', component: Layout, redirect: '/dashboard', children: [ { path: 'dashboard', component: () => import('@/views/dashboard/index'), name: 'Dashboard', meta: { title: 'Dashboard', icon: 'dashboard', affix: true } } ] }, { path: '/documentation', component: Layout, children: [ { path: 'index', component: () => import('@/views/documentation/index'), name: 'Documentation', meta: { title: 'Documentation', icon: 'documentation', affix: true } } ] }, { path: '/guide', component: Layout, redirect: '/guide/index', children: [ { path: 'index', component: () => import('@/views/guide/index'), name: 'Guide', meta: { title: 'Guide', icon: 'guide', noCache: true } } ] }, { path: '/profile', component: Layout, redirect: '/profile/index', hidden: true, children: [ { path: 'index', component: () => import('@/views/profile/index'), name: 'Profile', meta: { title: 'Profile', icon: 'user', noCache: true } } ] } ]
2.js代码
// 筛选路由(父路由和子路由)中包含affix: true的 filterAffixTags(routes, basePath = '/') { let tags = [] routes.forEach(route => { if (route.meta && route.meta.affix) { const tagPath = path.resolve(basePath, route.path) tags.push({ fullPath: tagPath, path: tagPath, name: route.name, meta: { ...route.meta } }) } if (route.children) { const tempTags = this.filterAffixTags(route.children, route.path) if (tempTags.length >= 1) { tags = [...tags, ...tempTags] } } }) return tags },
3.最后打印出来的tags的内容如下:
这篇关于通过递归的思维来获取:包含affix: true键值对路由器的绝对路径(父路由和子路由)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-25Java创意资料:新手入门的创意学习指南
- 2024-11-25JAVA对接阿里云智能语音服务资料详解:新手入门指南
- 2024-11-25Java对接阿里云智能语音服务资料详解
- 2024-11-25Java对接阿里云智能语音服务资料详解
- 2024-11-25JAVA副业资料:新手入门及初级提升指南
- 2024-11-25Java副业资料:入门到实践的全面指南
- 2024-11-25Springboot应用的多环境打包项目实战
- 2024-11-25SpringBoot应用的生产发布项目实战入门教程
- 2024-11-25Viite多环境配置项目实战:新手入门教程
- 2024-11-25Vite多环境配置项目实战入门教程