Browse Source
* 💥 feat: @umijs/route-utils replace getAuthorityFromRouter * fix test * remove unuse codepull/7368/head v4.3.0
committed by
GitHub
5 changed files with 19 additions and 127 deletions
@ -1,36 +0,0 @@ |
|||
import React from 'react'; |
|||
import { Redirect, connect, ConnectProps } from 'umi'; |
|||
import Authorized from '@/utils/Authorized'; |
|||
import { getRouteAuthority } from '@/utils/utils'; |
|||
import { ConnectState, UserModelState } from '@/models/connect'; |
|||
|
|||
interface AuthComponentProps extends ConnectProps { |
|||
user: UserModelState; |
|||
} |
|||
|
|||
const AuthComponent: React.FC<AuthComponentProps> = ({ |
|||
children, |
|||
route = { |
|||
routes: [], |
|||
}, |
|||
location = { |
|||
pathname: '', |
|||
}, |
|||
user, |
|||
}) => { |
|||
const { currentUser } = user; |
|||
const { routes = [] } = route; |
|||
const isLogin = currentUser && currentUser.name; |
|||
return ( |
|||
<Authorized |
|||
authority={getRouteAuthority(location.pathname, routes) || ''} |
|||
noMatch={isLogin ? <Redirect to="/exception/403" /> : <Redirect to="/user/login" />} |
|||
> |
|||
{children} |
|||
</Authorized> |
|||
); |
|||
}; |
|||
|
|||
export default connect(({ user }: ConnectState) => ({ |
|||
user, |
|||
}))(AuthComponent); |
|||
Loading…
Reference in new issue