作者 RuoYi

优化前端处理路由函数代码

@@ -82,28 +82,13 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) { @@ -82,28 +82,13 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
82 82
83 function filterChildren(childrenMap, lastRouter = false) { 83 function filterChildren(childrenMap, lastRouter = false) {
84 var children = [] 84 var children = []
85 - childrenMap.forEach((el, index) => {  
86 - if (el.children && el.children.length) {  
87 - if (el.component === 'ParentView' && !lastRouter) {  
88 - el.children.forEach(c => {  
89 - c.path = el.path + '/' + c.path  
90 - if (c.children && c.children.length) {  
91 - children = children.concat(filterChildren(c.children, c))  
92 - return  
93 - }  
94 - children.push(c)  
95 - })  
96 - return  
97 - }  
98 - }  
99 - if (lastRouter) {  
100 - el.path = lastRouter.path + '/' + el.path  
101 - if (el.children && el.children.length) {  
102 - children = children.concat(filterChildren(el.children, el))  
103 - return  
104 - } 85 + childrenMap.forEach(el => {
  86 + el.path = lastRouter ? lastRouter.path + '/' + el.path : el.path
  87 + if (el.children && el.children.length && el.component === 'ParentView') {
  88 + children = children.concat(filterChildren(el.children, el))
  89 + } else {
  90 + children.push(el)
105 } 91 }
106 - children = children.concat(el)  
107 }) 92 })
108 return children 93 return children
109 } 94 }