AuthorizedRoute.tsx 815 B

1234567891011121314151617181920212223242526272829303132
  1. import React from 'react';
  2. import { Route, Redirect } from 'umi';
  3. import Authorized from './Authorized';
  4. import { IAuthorityType } from './CheckPermissions';
  5. interface IAuthorizedRoutePops {
  6. currentAuthority: string;
  7. component: React.ComponentClass<any, any>;
  8. render: (props: any) => React.ReactNode;
  9. redirectPath: string;
  10. authority: IAuthorityType;
  11. }
  12. const AuthorizedRoute: React.SFC<IAuthorizedRoutePops> = ({
  13. component: Component,
  14. render,
  15. authority,
  16. redirectPath,
  17. ...rest
  18. }) => (
  19. <Authorized
  20. authority={authority}
  21. noMatch={<Route {...rest} render={() => <Redirect to={{ pathname: redirectPath }} />} />}
  22. >
  23. <Route
  24. {...rest}
  25. render={(props: any) => (Component ? <Component {...props} /> : render(props))}
  26. />
  27. </Authorized>
  28. );
  29. export default AuthorizedRoute;