fix: route root.children duplicate problem (#5755)
Co-authored-by: anyup <anyupxing@163.com>pull/62/head
							parent
							
								
									2e80c773db
								
							
						
					
					
						commit
						5bace9de1f
					
				|  | @ -30,6 +30,9 @@ async function generateAccessible( | ||||||
| 
 | 
 | ||||||
|   const root = router.getRoutes().find((item) => item.path === '/'); |   const root = router.getRoutes().find((item) => item.path === '/'); | ||||||
| 
 | 
 | ||||||
|  |   // 获取已有的路由名称列表
 | ||||||
|  |   const names = root?.children?.map((item) => item.name) ?? []; | ||||||
|  | 
 | ||||||
|   // 动态添加到router实例内
 |   // 动态添加到router实例内
 | ||||||
|   accessibleRoutes.forEach((route) => { |   accessibleRoutes.forEach((route) => { | ||||||
|     if (root && !route.meta?.noBasicLayout) { |     if (root && !route.meta?.noBasicLayout) { | ||||||
|  | @ -38,7 +41,10 @@ async function generateAccessible( | ||||||
|       if (route.children && route.children.length > 0) { |       if (route.children && route.children.length > 0) { | ||||||
|         delete route.component; |         delete route.component; | ||||||
|       } |       } | ||||||
|  |       // 根据router name判断,如果路由已经存在,则不再添加
 | ||||||
|  |       if (!names?.includes(route.name)) { | ||||||
|         root.children?.push(route); |         root.children?.push(route); | ||||||
|  |       } | ||||||
|     } else { |     } else { | ||||||
|       router.addRoute(route); |       router.addRoute(route); | ||||||
|     } |     } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 anyup
						anyup