quanyawei
2024-06-17 19cf5b237b0e2bf489c0fe0f8929bf992fae5f8f
src/router/dynamicRouter.js
@@ -354,5 +354,17 @@
    // currentRoutes.splice(currentRoutes.length, 0, notFound)
  }
  console.log('currentRoutes', currentRoutes)
  router.addRoutes(currentRoutes)
  const uniqueRoutes = removeDuplicateRoutes(currentRoutes)
  console.log('uniqueRoutes', uniqueRoutes)
  router.addRoutes(uniqueRoutes)
}
function removeDuplicateRoutes(routes) {
  const routeNames = new Set()
  return routes.filter(route => {
    if (routeNames.has(route.path)) {
      return false // 如果名称已存在,则过滤掉这条路由
    }
    routeNames.add(route.path) // 添加名称到集合中
    return true
  })
}