title: How to redirect to home page if URL is invalid?
body: <p>I am using React and React-router v4</p>
  
  <p>Here is my route component:</p>
  
  <pre><code>&lt;Switch&gt;
                {/* &lt;Route path='/blog' exact component={Blog} /&gt; */}
                &lt;Route path='/projects/:id' component={ProjectDetails} /&gt;
                &lt;Route path='/career/:id' component={CareerDetails} /&gt;
                &lt;Route path='/' component={withScrollPreservation(LandingPage)} /&gt;
                &lt;Route component={withScrollPreservation(LandingPage)} /&gt;
              &lt;/Switch&gt;
  </code></pre>
  
  <p>What is my question:</p>
  
  <p>If user types something that is not valid from routes give I want it to redirect to home page. Consider this scenario running this locally:</p>
  
  <p><code>localhost:4000/</code> - home page</p>
  
  <p><code>localhiost:4000/invalidurl</code> - should redirect back to <code>localhost:4000/</code> and deleteting invalidurl from url</p>
  
  <p>Any thoughts?</p>