[Web front-end] react router4.0 browsing page after login before returning (back to the source page)

This link: https: //blog.csdn.net/zeroyulong/article/details/81911704
troubled by the problem for a long time, finally found the answer in the official document (see the English documentation really uncomfortable ah ~ ~)

Official documents address: https: //reacttraining.com/react-router/web/example/auth-workflow

1. Source page Jump login button:

This page will be stored in the routing state in the pathname,

<Link to={{
    pathname:"/login",
    state:{from:this.props.location.pathname}
}} className="name-load">去登录</Link>

  


2. Go to the login page for the source of the page is redirected to the source of the page after logging is completed (determine whether the source of the page, if the user direct access to the login page, you can not get state, you should provide a default home page for users Jump)

// Origin records 
the let from; 
IF (! This.props.location.state = null) { 
    from = this.props.location.state.from 
} 
const = urlTo from || '/ the App'; 

return ( 
    <div> 
        { this.props.isAuth <Redirect to urlTo} = {/>:? null} 
        <the p-> you do not have permission, you need to be logged in to see </ the p-> 
        <this.props.login the Button onClick = {}> point I log </ Button> 
    </ div> 
)

 

Guess you like

Origin www.cnblogs.com/0616--ataozhijia/p/11351528.html