diff --git a/src/pages/Authorized.js b/src/pages/Authorized.js index 875e1239d7c3a912073d6803dcbbc369cc25a60e..960f2c6b68e4d489968801317c3ba0d9a898b645 100644 --- a/src/pages/Authorized.js +++ b/src/pages/Authorized.js @@ -6,28 +6,20 @@ import Authorized from '@/utils/Authorized'; function AuthComponent({ children, location, routerData, status }) { const isLogin = status === 'ok'; + const getRouteAuthority = (path, routeData) => { + let authorities; + routeData.forEach(route => { + // match prefix + if (pathToRegexp(`${route.path}(.*)`).test(path)) { + authorities = route.authority || authorities; - const getRouteAuthority = (pathname, routeData) => { - const routes = routeData.slice(); // clone - - const getAuthority = (routeDatas, path) => { - let authorities; - routeDatas.forEach(route => { - // check partial route - if (pathToRegexp(`${route.path}(.*)`).test(path)) { - if (route.authority) { - authorities = route.authority; - } - // is exact route? - if (!pathToRegexp(route.path).test(path) && route.routes) { - authorities = getAuthority(route.routes, path); - } + // get children authority recursively + if (route.routes) { + authorities = getRouteAuthority(path, route.routes) || authorities; } - }); - return authorities; - }; - - return getAuthority(routes, pathname); + } + }); + return authorities; }; return (