AuthorizedRoute.js 639 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 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
import Authorized from './Authorized';

class AuthorizedRoute extends React.Component {
  render() {
    const { component: Component, render, authority,
      redirectPath, ...rest } = this.props;
    return (
      <Authorized
        authority={authority}
        noMatch={<Route {...rest} render={() => <Redirect to={{ pathname: redirectPath }} />} />}
      >
        <Route
          {...rest}
          render={props => (Component ? <Component {...props} /> : render(props))}
        />
      </Authorized>
    );
  }
}

export default AuthorizedRoute;