title: ReactJS Login with redirect if authenticated
body: <p>I am trying to put together a simple login system with a Laravel backend.</p>
  
  <p>I have:</p>
  
  <p><strong>Login.js</strong></p>
  
  <pre><code>import React, { Component } from 'react';
  import ReactDOM from 'react-dom';
  
  export default class Login extends Component {
  
      componentWillMount() {
          // do something like setting default state
      }
  
      processSubmit(values) {
          // do something with the values
      }
  
      render() {
          const { handleSubmit, submitting } = this.props;
  
          return (
              &lt;div className="container mt-5"&gt;
                  &lt;div className="row justify-content-center"&gt;
                      &lt;div className="col-6"&gt;
                          &lt;div className="card"&gt;
                              &lt;div className="card-body"&gt;
                                  &lt;h2 className="text-center font-weight-light mb-4"&gt;Sign into your account&lt;/h2&gt;
  
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          );
      }
  };
  </code></pre>
  
  <p>When successfully logged in, redirect to dashboard...</p>
  
  <p><strong>Dashboard.js</strong></p>
  
  <pre><code>import React, { Component } from 'react';
  import ReactDOM from 'react-dom';
  
  export default class Dashboard extends Component {
  
      render() {
          return &lt;div&gt;
  
          &lt;/div&gt;
      }
  
  }
  </code></pre>
  
  <p><strong>App.js</strong></p>
  
  <pre><code>import React, {Component} from 'react'
  import ReactDOM from 'react-dom'
  import {BrowserRouter, Route, Switch} from 'react-router-dom'
  import Home from '../containers/Home';
  import Login from '../containers/LogIn';
  import CreateUsers from '../containers/CreateUsers';
  import Dashboard from '../containers/Dashboard';
  import NavBar from './NavBar';
  
  class App extends Component {
      constructor(props) {
          super(props);
  
          this.state = {
              isAuthenticated: false
          };
      }
  
      userHasAuthenticated = authenticated =&gt; {
          this.setState({isAuthenticated: authenticated});
      };
  
      render() {
          return (
              &lt;BrowserRouter&gt;
                  &lt;div&gt;
                      &lt;NavBar /&gt;
                      &lt;Route exact path="/" component={Home}/&gt;
                      &lt;Route path="/login" component={Login}/&gt;
                      &lt;Route path="/users/create" component={CreateUsers}/&gt;
                      &lt;Route path="/dashboard" component={Dashboard}/&gt;
                  &lt;/div&gt;
              &lt;/BrowserRouter&gt;
          )
      }
  }
  
  ReactDOM.render(&lt;App /&gt;, document.getElementById('app'))
  </code></pre>
  
  <p>How do I get it to redirect the user to the login page if they are not authenticated and same with if they are send them to the dashboard/home page?</p>