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
parent
commit
d52c453965
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      config/config.ts
  2. 8
      src/utils/utils.ts

9
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',

8
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 = <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;
};

Loading…
Cancel
Save