import Authorized from '@/utils/Authorized'; import { connect } from 'dva'; import pathToRegexp from 'path-to-regexp'; import React from 'react'; import Redirect from 'umi/redirect'; interface IAuthComponentProps { location: Location; routerData: any[]; status: string; } const AuthComponent: React.FC = ({ children, location, routerData, status, }) => { const isLogin = status === 'ok'; const getRouteAuthority = (path, routeData) => { let authorities; routeData.forEach(route => { // match prefix if (pathToRegexp(`${route.path}(.*)`).test(path)) { authorities = route.authority || authorities; // get children authority recursively if (route.routes) { authorities = getRouteAuthority(path, route.routes) || authorities; } } }); return authorities; }; return ( : } > {children} ); }; export default connect(({ menu: menuModel, login: loginModel }) => ({ routerData: menuModel.routerData, status: loginModel.status, }))(AuthComponent);