AuthorizedRoute.js 605 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() {
jim's avatar
jim committed
7
    const { component: Component, render, authority, redirectPath, ...rest } = this.props;
ddcat1115's avatar
ddcat1115 committed
8 9 10
    return (
      <Authorized
        authority={authority}
jim's avatar
jim committed
11
        noMatch={<Route {...rest} render={() => <Redirect to={{ pathname: redirectPath }} />} />}
ddcat1115's avatar
ddcat1115 committed
12
      >
jim's avatar
jim committed
13
        <Route {...rest} render={props => (Component ? <Component {...props} /> : render(props))} />
ddcat1115's avatar
ddcat1115 committed
14 15 16 17 18 19
      </Authorized>
    );
  }
}

export default AuthorizedRoute;