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', icon: 'crown',
component: './Admin', component: './Admin',
authority: ['admin'], authority: ['admin'],
routes: [
{
path: '/admin/sub-page',
name: 'sub-page',
icon: 'smile',
component: './Welcome',
authority: ['admin'],
},
],
}, },
{ {
component: './404', component: './404',

8
src/utils/utils.ts

@ -30,11 +30,15 @@ export const getPageQuery = () => parse(window.location.href.split('?')[1]);
* @param router [{}] * @param router [{}]
* @param pathname string * @param pathname string
*/ */
export const getAuthorityFromRouter = <T extends { path?: string }>( export const getAuthorityFromRouter = <T extends Route>(
router: T[] = [], router: T[] = [],
pathname: string, pathname: string,
): T | undefined => { ): 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; if (authority) return authority;
return undefined; return undefined;
}; };

Loading…
Cancel
Save