title: Redirecting not working properly in react
body: <h2>What I want:</h2>
  
  <p>I have a private route (/dashboard) which can be only accessible when a user is logged in. So the condition I have is that load Dashboard only when the user is Authenticated and Loading is false (Completed). If the user is Not authenticated, redirect him to the login page.</p>
  
  <h2>Problem</h2>
  
  <p>My code is working fine if I click on the Dashboard Link from the navbar. It redirects me to Dashboard if I am logged in but the problem comes when I try to manually go to dashboard by directly typing localhost:3000/dashboard.
  Even if I refresh the dashboard it redirects me to login page.</p>
  
  <h2>Reason</h2>
  
  <p>So the reason for this problem is that the two states (authentication and loading) are in Redux, so if I directly access the dashboard, redux takes some time to login the user and change the states due to which I go back to Home page even if I am logged in.</p>
  
  <p><a href="https://i.stack.imgur.com/M0Ncv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M0Ncv.png" alt="enter image description here"></a></p>
  
  <p>It takes some time because I have a token in local storage and which is checked by sending post request to backend to confirm if the token is valid, on Valid token, I get the user to redux state.</p>
  
  <h2>Code</h2>
  
  <p>in <strong>App.js</strong></p>
  
  <pre><code>&lt;Switch&gt;
            &lt;Route exact path="/register" component={Register} /&gt;
            &lt;Route exact path="/login" component={Login} /&gt;
            &lt;PrivateRoute exact path="/dashboard" component={
  &lt;/Switch&gt;
  </code></pre>
  
  <p><strong>PrivateRoute.js</strong></p>
  
  <pre><code>const PrivateRoute = props =&gt; {
    let route = &lt;Route {...props} component={props.component} /&gt;;
  
    if (!props.isLoading &amp;&amp; !props.isAuthenticated) {
      route = &lt;Redirect to="/login" /&gt;;
    }
    return &lt;React.Fragment&gt;{route}&lt;/React.Fragment&gt;;
  }
  </code></pre>
  
  <p>You can see that the condition is checked instantly in Private Route due to which user is redirected to home page if he manually goes to /dashboard.</p>
  
  <p>How can I solve this issue?</p>
  
  <p><strong>PROBLEM SOLVED:</strong> 
  I have a little typo due to which isLoading was undefined always. By fixing that, it's working fine</p>