title: React router v4 redirect when no match
body: <p>I'm new to react-router (and client side routing in general) so I might be thinking about this all wrong. Sorry in advance if that is the case...</p>
  
  <p>Basically just want to implement 3 simple rules: </p>
  
  <ul>
  <li>if no user, redirect to '/login'</li>
  <li>else if route doesn't exist, redirect to '/' (root)</li>
  <li>else let user go to requested route</li>
  </ul>
  
  <p>I keep track of the user in <code>this.state.user</code>. My current router seems to follow the first 2 rules, but only lets the authenticated user see the home page ('/profile' redirects to '/') so I know I'm doing something wrong but can't figure out what.</p>
  
  <pre class="lang-js prettyprint-override"><code> &lt;Router&gt;
      {this.state.user ? (
        &lt;Switch&gt;
          &lt;Route path="/" exact component={Home}/&gt;
          &lt;Route path="/profile" exact component={Profile}/&gt;
          &lt;Route render={() =&gt; (&lt;Redirect to="/" /&gt;)}/&gt;
        &lt;/Switch&gt;
      ) : (
        &lt;Switch&gt;
          &lt;Route path="/login" exact component={Login}/&gt;
          &lt;Route render={() =&gt; (&lt;Redirect to="/login" /&gt;)}/&gt;
        &lt;/Switch&gt;
      )}
   &lt;/Router&gt;
  </code></pre>
  
  <p>Any advice is appreciated. Thank you</p>