AuthorizedRoute.js 744 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() {
7 8 9 10 11 12 13
    const {
      component: Component,
      render,
      authority,
      redirectPath,
      ...rest
    } = this.props;
ddcat1115's avatar
ddcat1115 committed
14 15 16
    return (
      <Authorized
        authority={authority}
17 18 19 20 21 22
        noMatch={
          <Route
            {...rest}
            render={() => <Redirect to={{ pathname: redirectPath }} />}
          />
        }
ddcat1115's avatar
ddcat1115 committed
23 24 25
      >
        <Route
          {...rest}
26 27 28
          render={props =>
            (Component ? <Component {...props} /> : render(props))
          }
ddcat1115's avatar
ddcat1115 committed
29 30 31 32 33 34 35
        />
      </Authorized>
    );
  }
}

export default AuthorizedRoute;