zhou zhou
4 天以前 aaf8a50511d77dbc209ca93bbba308c21179a8bc
rsf-design/src/router/guards/beforeEach.js
@@ -99,20 +99,41 @@
  })
  return false
}
function normalizeRoutePathSegment(path = '') {
  if (!path) {
    return ''
  }
  return path.replace(/^\/+/, '').replace(/\/+$/, '')
}
function joinRoutePath(parentPath = '', childPath = '') {
  if (!childPath) {
    return parentPath || '/'
  }
  if (childPath.startsWith('/')) {
    return childPath
  }
  const normalizedParent = parentPath === '/' ? '' : normalizeRoutePathSegment(parentPath)
  const normalizedChild = normalizeRoutePathSegment(childPath)
  const fullPath = [normalizedParent, normalizedChild].filter(Boolean).join('/')
  return `/${fullPath}`.replace(/\/+/g, '/')
}
function isStaticRoute(path) {
  const checkRoute = (routes, targetPath) => {
  const checkRoute = (routes, targetPath, parentPath = '') => {
    return routes.some((route) => {
      if (route.name === 'Exception404') {
        return false
      }
      const routePath = route.path
      const routePath = joinRoutePath(parentPath, route.path)
      const pattern = routePath.replace(/:[^/]+/g, '[^/]+').replace(/\*/g, '.*')
      const regex = new RegExp(`^${pattern}$`)
      if (regex.test(targetPath)) {
        return true
      }
      if (route.children && route.children.length > 0) {
        return checkRoute(route.children, targetPath)
        return checkRoute(route.children, targetPath, routePath)
      }
      return false
    })