Created
December 8, 2018 19:41
-
-
Save XiongJingzhi/3ca12e167391035814608b35a6447348 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import { withRouter } from 'react-router' | |
import { Route, Redirect } from 'react-router-dom' | |
class AuthRouter extends Component { | |
render() { | |
const { component: Component, ...rest } = this.props | |
const isLogged = sessionStorage.getItem("isLogin") === "1" ? true : false; | |
return ( | |
<Route {...rest} render={props => { | |
return isLogged | |
? <Component {...props} /> | |
: <Redirect to="/login" /> | |
}} /> | |
) | |
} | |
} | |
export default withRouter(AuthRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
render(){ | |
return ( | |
<Router> | |
<App> | |
<Switch> | |
<Route path="/" exact component={Login}></Route> | |
<Route path="/login" component={Login}></Route> | |
{/*登录权限控制组件*/} | |
<AuthRouter path='/main' component={Home}></AuthRouter> | |
</Switch> | |
</App> | |
</Router> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment