import React from 'react'; import Redirect from 'umi/redirect'; import pathToRegexp from 'path-to-regexp'; import { connect } from 'dva'; import Authorized from '@/utils/Authorized'; function AuthComponent({ children, location, routerData, currentCuser }) { const isLogin = currentCuser && currentCuser.name; 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, user: userModel }) => ({ routerData: menuModel.routerData, currentCuser: userModel.currentCuser, }))(AuthComponent);