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

const AuthorizedRoute = ({
6
  component: Component,
dengxiaofeng's avatar
dengxiaofeng committed
7 8 9 10
  render,
  authority,
  redirectPath,
  ...rest
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
}) => (
  <Authorized
    authority={authority}
    noMatch={
      <Route
        {...rest}
        render={() => <Redirect to={{ pathname: redirectPath }} />}
      />
    }
  >
    <Route
      {...rest}
      render={props => (Component ? <Component {...props} /> : render(props))}
    />
  </Authorized>
);
dengxiaofeng's avatar
dengxiaofeng committed
27 28

export default AuthorizedRoute;