AuthorizedRoute.js 647 Bytes
Newer Older
ddcat1115's avatar
ddcat1115 committed
1
import React from 'react';
2
import { Route, Redirect } from 'react-router-dom';
ddcat1115's avatar
ddcat1115 committed
3 4 5 6
import Authorized from './Authorized';

class AuthorizedRoute extends React.Component {
  render() {
xiaohu's avatar
xiaohu committed
7
    // TODO: umi只会返回render和rest
jim's avatar
jim committed
8
    const { component: Component, render, authority, redirectPath, ...rest } = this.props;
ddcat1115's avatar
ddcat1115 committed
9 10 11
    return (
      <Authorized
        authority={authority}
jim's avatar
jim committed
12
        noMatch={<Route {...rest} render={() => <Redirect to={{ pathname: redirectPath }} />} />}
ddcat1115's avatar
ddcat1115 committed
13
      >
jim's avatar
jim committed
14
        <Route {...rest} render={props => (Component ? <Component {...props} /> : render(props))} />
ddcat1115's avatar
ddcat1115 committed
15 16 17 18 19 20
      </Authorized>
    );
  }
}

export default AuthorizedRoute;