title: React Router Redirect after Login not working properly
body: <p>I'm developing a basic react application and included react-router. 
  I have a simple authentication control with the Local Storage. </p>
  
  <p>After a user inputs username and password and clicks login, I do an HTTP call and take response from the server with Axios. Then I set the localStorage 'user' item.</p>
  
  <p>To protect a route I implemented the PrivateRoute component where I check if 'user' in localStorage is set.</p>
  
  <p>I already tried to move set Local Storage inside then() in the Axios HTTP call but nothing changed.</p>
  
  <p>Api CALL</p>
  
  <pre><code>  loginUser (username,password) {
      return HTTP.post('/login',  null, { params: {
        username,
        password
      }})
  
  
      Api.loginUser(username,password)
          .then( (response) =&gt; {
              console.log("Response DATA");
              Api.saveUserData(response.data);
              this.setState({ redirect: true });
          })
  </code></pre>
  
  <p>RENDER METHOD</p>
  
  <pre><code>if (this.state.redirect === true) {
      return &lt;Redirect to='/home'/&gt;;
  }
  </code></pre>
  
  <p>APP COMPONENT</p>
  
  <pre><code>    class App extends Component {
  
        render() {
          return (
            &lt;Router&gt;
              &lt;Route path="/login" component={Login} /&gt;
              &lt;PrivateRoute path="/home" component={Home} /&gt;
            &lt;/Router&gt;
          );
        }
      }
  </code></pre>
  
  <p>PRIVATE ROUTE COMPONENT</p>
  
  <pre><code>    const PrivateRoute = ({ component: Component, ...rest }) =&gt; {
  
        const isLoggedIn = AuthService.isAuthenticated();
  
        return (
          &lt;Route
            {...rest}
            render={props =&gt;
              isLoggedIn ? (
                &lt;Component {...props} /&gt;
              ) : (
                &lt;Redirect to={{ pathname: '/login', state: { from: props.location } }} /&gt;
              )
            }
          /&gt;
        )
      }
  </code></pre>
  
  <p>The problems seem to be: the local storage is set after the redirect because is null. So I get blank page instead of loading the Home Component. If i refresh the page, the code works fine.</p>