ソースを参照

fix: hasLogin redirect to login page

xiaohuoni 6 年 前
コミット
c7e4983a06
1 ファイル変更7 行追加6 行削除
  1. 7 6
      src/pages/Authorized.js

+ 7 - 6
src/pages/Authorized.js

@@ -3,9 +3,12 @@ import Redirect from 'umi/redirect';
 import pathToRegexp from 'path-to-regexp';
 import pathToRegexp from 'path-to-regexp';
 import { connect } from 'dva';
 import { connect } from 'dva';
 import Authorized from '@/utils/Authorized';
 import Authorized from '@/utils/Authorized';
+import { getAuthority } from '@/utils/authority';
+import Exception403 from '@/pages/Exception/403';
 
 
-function AuthComponent({ children, location, routerData, status }) {
-  const isLogin = status === 'ok';
+function AuthComponent({ children, location, routerData }) {
+  const auth = getAuthority();
+  const isLogin = auth && auth[0] !== 'guest';
   const getRouteAuthority = (path, routeData) => {
   const getRouteAuthority = (path, routeData) => {
     let authorities;
     let authorities;
     routeData.forEach(route => {
     routeData.forEach(route => {
@@ -21,17 +24,15 @@ function AuthComponent({ children, location, routerData, status }) {
     });
     });
     return authorities;
     return authorities;
   };
   };
-
   return (
   return (
     <Authorized
     <Authorized
       authority={getRouteAuthority(location.pathname, routerData)}
       authority={getRouteAuthority(location.pathname, routerData)}
-      noMatch={isLogin ? <Redirect to="/exception/403" /> : <Redirect to="/user/login" />}
+      noMatch={isLogin ? <Exception403 /> : <Redirect to="/user/login" />}
     >
     >
       {children}
       {children}
     </Authorized>
     </Authorized>
   );
   );
 }
 }
-export default connect(({ menu: menuModel, login: loginModel }) => ({
+export default connect(({ menu: menuModel }) => ({
   routerData: menuModel.routerData,
   routerData: menuModel.routerData,
-  status: loginModel.status,
 }))(AuthComponent);
 }))(AuthComponent);