title: Javascript React redirect if session variable is set
body: <p>I am using react. I have a login page which I don't want the user to be able to visit if a variable is set to true.</p>
  
  <p>I am using sessionStorage after the user logs in and setting a variable to true:</p>
  
  <pre><code> sessionStorage.setItem('loggedin', 'true');
  </code></pre>
  
  <p>My problem is that the use is still able to visit the login page.</p>
  
  <p>How do I disallow the use to visit this page if loggedin is set to true?</p>
  
  <p>Here's my current App Component:</p>
  
  <pre><code>class App extends React.Component {
  
    render() {
      return (
        &lt;Router&gt;
          &lt;div&gt;
            &lt;Nav /&gt;
            &lt;Route exact path="/" component={Home} /&gt;
            &lt;Route exact path="/contact" component={contact} /&gt;
            &lt;Route path="/login" component={Login} /&gt;
          &lt;/div&gt;
        &lt;/Router&gt;
      )
    }
  </code></pre>