AuthorizedRoute.js 529 Bytes
Newer Older
ddcat1115's avatar
ddcat1115 committed
1
import React from 'react';
2
import { Route, Redirect } from 'umi';
ddcat1115's avatar
ddcat1115 committed
3 4
import Authorized from './Authorized';

afc163's avatar
afc163 committed
5 6 7 8 9 10 11 12 13
// TODO: umi只会返回render和rest
const AuthorizedRoute = ({ component: Component, render, authority, redirectPath, ...rest }) => (
  <Authorized
    authority={authority}
    noMatch={<Route {...rest} render={() => <Redirect to={{ pathname: redirectPath }} />} />}
  >
    <Route {...rest} render={props => (Component ? <Component {...props} /> : render(props))} />
  </Authorized>
);
ddcat1115's avatar
ddcat1115 committed
14 15

export default AuthorizedRoute;