diff --git a/config/router.config.js b/config/router.config.js
index 840fe8334989fc4035947800767869c881018621..0f54cc05812f3499f7fe536e166600589242fa51 100644
--- a/config/router.config.js
+++ b/config/router.config.js
@@ -19,7 +19,6 @@ export default [
path: '/',
component: '../layouts/BasicLayout',
Routes: ['src/pages/Authorized'],
- authority: ['admin', 'user'],
routes: [
// dashboard
{ path: '/', redirect: '/dashboard/analysis' },
diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js
index 338968764205ff7caed5c6042f0e5c459f237e5d..06cc41fce542df11b491a8f244f559a8936f7b1e 100644
--- a/src/layouts/BasicLayout.js
+++ b/src/layouts/BasicLayout.js
@@ -4,14 +4,11 @@ import DocumentTitle from 'react-document-title';
import { connect } from 'dva';
import { ContainerQuery } from 'react-container-query';
import classNames from 'classnames';
-import pathToRegexp from 'path-to-regexp';
import Media from 'react-media';
-import Authorized from '@/utils/Authorized';
import logo from '../assets/logo.svg';
import Footer from './Footer';
import Header from './Header';
import Context from './MenuContext';
-import Exception403 from '../pages/Exception/403';
import PageLoading from '@/components/PageLoading';
import SiderMenu from '@/components/SiderMenu';
import getPageTitle from '@/utils/getPageTitle';
@@ -73,29 +70,6 @@ class BasicLayout extends React.Component {
};
}
- getRouteAuthority = (pathname, routeData) => {
- const routes = routeData.slice(); // clone
-
- const getAuthority = (routeDatas, path) => {
- let authorities;
- routeDatas.forEach(route => {
- // check partial route
- if (pathToRegexp(`${route.path}(.*)`).test(path)) {
- if (route.authority) {
- authorities = route.authority;
- }
- // is exact route?
- if (!pathToRegexp(route.path).test(path) && route.routes) {
- authorities = getAuthority(route.routes, path);
- }
- }
- });
- return authorities;
- };
-
- return getAuthority(routes, pathname);
- };
-
getLayoutStyle = () => {
const { fixSiderbar, isMobile, collapsed, layout } = this.props;
if (fixSiderbar && layout !== 'topmenu' && !isMobile) {
@@ -132,12 +106,10 @@ class BasicLayout extends React.Component {
isMobile,
menuData,
breadcrumbNameMap,
- route: { routes },
fixedHeader,
} = this.props;
const isTop = PropsLayout === 'topmenu';
- const routerConfig = this.getRouteAuthority(pathname, routes);
const contentStyle = !fixedHeader ? { paddingTop: 0 } : {};
const layout = (
@@ -165,9 +137,7 @@ class BasicLayout extends React.Component {
{...this.props}
/>
- }>
- {children}
-
+ {children}
diff --git a/src/models/menu.js b/src/models/menu.js
index 218c706513ea54fb2eb97ef0e2baf7195a8608b3..f04991631e21dab92dd2f07f756339aa84d599c7 100644
--- a/src/models/menu.js
+++ b/src/models/menu.js
@@ -97,6 +97,7 @@ export default {
state: {
menuData: [],
+ routerData: [],
breadcrumbNameMap: {},
},
@@ -107,7 +108,7 @@ export default {
const breadcrumbNameMap = memoizeOneGetBreadcrumbNameMap(menuData);
yield put({
type: 'save',
- payload: { menuData, breadcrumbNameMap },
+ payload: { menuData, breadcrumbNameMap, routerData: routes },
});
},
},
diff --git a/src/pages/Authorized.js b/src/pages/Authorized.js
index c29d9610e7b2873c8ca5e0085a865cfc6ab9ffb0..875e1239d7c3a912073d6803dcbbc369cc25a60e 100644
--- a/src/pages/Authorized.js
+++ b/src/pages/Authorized.js
@@ -1,13 +1,44 @@
import React from 'react';
-import RenderAuthorized from '@/components/Authorized';
-import { getAuthority } from '@/utils/authority';
import Redirect from 'umi/redirect';
+import pathToRegexp from 'path-to-regexp';
+import { connect } from 'dva';
+import Authorized from '@/utils/Authorized';
-const Authority = getAuthority();
-const Authorized = RenderAuthorized(Authority);
+function AuthComponent({ children, location, routerData, status }) {
+ const isLogin = status === 'ok';
-export default ({ children }) => (
- }>
- {children}
-
-);
+ const getRouteAuthority = (pathname, routeData) => {
+ const routes = routeData.slice(); // clone
+
+ const getAuthority = (routeDatas, path) => {
+ let authorities;
+ routeDatas.forEach(route => {
+ // check partial route
+ if (pathToRegexp(`${route.path}(.*)`).test(path)) {
+ if (route.authority) {
+ authorities = route.authority;
+ }
+ // is exact route?
+ if (!pathToRegexp(route.path).test(path) && route.routes) {
+ authorities = getAuthority(route.routes, path);
+ }
+ }
+ });
+ return authorities;
+ };
+
+ return getAuthority(routes, pathname);
+ };
+ return (
+ : }
+ >
+ {children}
+
+ );
+}
+export default connect(({ menu: menuModel, login: loginModel }) => ({
+ routerData: menuModel.routerData,
+ status: loginModel.status,
+}))(AuthComponent);