Skip to content

Commit

Permalink
Update AuthorizedRoute.js
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohuoni authored May 19, 2018
1 parent 775d63c commit 74ad474
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/components/Authorized/AuthorizedRoute.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
import React from 'react';
import { Route, Redirect } from 'react-router-dom';
import Authorized from './Authorized';
import { getRouterData } from 'common/router';

//umi只会返回render和rest
class AuthorizedRoute extends React.Component {
render() {
const { component: Component, render, authority, redirectPath, ...rest } = this.props;
const {
render,
path,
...rest
} = this.props;
const routerData = getRouterData({});
const redirectPath = '/User/Login';
const authority = routerData[path].authority;
return (
<Authorized
authority={authority}
noMatch={<Route {...rest} render={() => <Redirect to={{ pathname: redirectPath }} />} />}
noMatch={
<Route
{...rest}
render={() => <Redirect to={{ pathname: redirectPath }} />}
/>
}
>
<Route {...rest} render={props => (Component ? <Component {...props} /> : render(props))} />
<Route
{...rest}
render={props =>render(props)}
/>
</Authorized>
);
}
Expand Down

0 comments on commit 74ad474

Please sign in to comment.