From 837b8c232d3ae4127db6ccf1117f5ebec6f3c029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B0=8F=E8=81=AA?= Date: Thu, 14 Feb 2019 09:54:29 +0800 Subject: [PATCH] route authority attribute behavior no use while (#3522) * route authority attribute behavior no use while --- src/layouts/BasicLayout.js | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index 89a706a1..c992fb2b 100644 --- a/src/layouts/BasicLayout.js +++ b/src/layouts/BasicLayout.js @@ -90,27 +90,25 @@ class BasicLayout extends React.Component { getRouteAuthority = (pathname, routeData) => { const routes = routeData.slice(); // clone - let authorities; - - while (routes.length > 0) { - const route = routes.shift(); - // check partial route - if (pathToRegexp(`${route.path}(.*)`).test(pathname)) { - if (route.authority) { - authorities = route.authority; - } - // is exact route? - if (pathToRegexp(route.path).test(pathname)) { - break; - } - if (route.routes) { - route.routes.forEach(r => routes.push(r)); + 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); + } } - } - } + }); + return authorities; + }; - return authorities; + return getAuthority(routes, pathname); }; getPageTitle = (pathname, breadcrumbNameMap) => { -- GitLab