From d52c453965dcceca1b0f59e9169eb9e56e80eab9 Mon Sep 17 00:00:00 2001 From: NarApp Date: Fri, 7 Feb 2020 04:49:59 +0300 Subject: [PATCH] fixes/Route Recursive Authority #5931 (#5933) * fixes/Route Recursive Authority #5931 * fixes/Route Recursive Authority --- config/config.ts | 9 +++++++++ src/utils/utils.ts | 8 ++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/config/config.ts b/config/config.ts index 12835484..d4209c29 100644 --- a/config/config.ts +++ b/config/config.ts @@ -113,6 +113,15 @@ export default { icon: 'crown', component: './Admin', authority: ['admin'], + routes: [ + { + path: '/admin/sub-page', + name: 'sub-page', + icon: 'smile', + component: './Welcome', + authority: ['admin'], + }, + ], }, { component: './404', diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 82e14a32..9ba73c20 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -30,11 +30,15 @@ export const getPageQuery = () => parse(window.location.href.split('?')[1]); * @param router [{}] * @param pathname string */ -export const getAuthorityFromRouter = ( +export const getAuthorityFromRouter = ( router: T[] = [], pathname: string, ): T | undefined => { - const authority = router.find(({ path }) => path && pathRegexp(path).exec(pathname)); + const authority = router.find( + ({ routes, path = '/' }) => + (path && pathRegexp(path).exec(pathname)) || + (routes && getAuthorityFromRouter(routes, pathname)), + ); if (authority) return authority; return undefined; };