ソースを参照

fixes/Route Recursive Authority #5931 (#5933)

* fixes/Route Recursive Authority #5931

* fixes/Route Recursive Authority
NarApp 6 年 前
コミット
d52c453965
2 ファイル変更15 行追加2 行削除
  1. 9 0
      config/config.ts
  2. 6 2
      src/utils/utils.ts

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

+ 6 - 2
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;
 };