Browse Source
fixes/Route Recursive Authority #5931 (#5933)
* fixes/Route Recursive Authority #5931
* fixes/Route Recursive Authority
pull/5945/head
NarApp
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
15 additions and
2 deletions
-
config/config.ts
-
src/utils/utils.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', |
|
|
|
|
|
|
|
@ -30,11 +30,15 @@ export const getPageQuery = () => parse(window.location.href.split('?')[1]); |
|
|
|
* @param router [{}] |
|
|
|
* @param pathname string |
|
|
|
*/ |
|
|
|
export const getAuthorityFromRouter = <T extends { path?: string }>( |
|
|
|
export const getAuthorityFromRouter = <T extends Route>( |
|
|
|
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; |
|
|
|
}; |
|
|
|
|