title: check if route is valid react router
body: <p>I am using react router v5 and would like to check my routes to make sure they are valid as my 404 page is not triggering when an invalid link is shown presumably because the route still matches even though there is no item to display on the route as it's invalid. e.g <code>example.com/cat1/product1</code> being valid and <code>example.com/cat1/produc1</code> being invalid.</p>
  <p>The same for the categories <code>example.com/cat1</code> being valid and <code>example.com/ca1</code> being invalid.</p>
  <p>Currently it just shows no content for the invalid link instead of my <code>NotFound</code> component.</p>
  <p>How can I check each link to see if it is valid and if not display my <code>NotFound</code> component?</p>
  <pre><code>  &lt;Switch&gt;
              &lt;Route exact path=&quot;/&quot;&gt;
                &lt;Home categories={categories} products={products} /&gt;
              &lt;/Route&gt;
              &lt;Route exact path=&quot;/product-categories&quot;&gt;
                &lt;Products categories={categories} /&gt;
              &lt;/Route&gt;
              &lt;Route exact path=&quot;/delivery&quot;&gt;
                &lt;Delivery categories={categories} /&gt;
              &lt;/Route&gt;
              &lt;Route exact path=&quot;/terms&quot;&gt;
                &lt;Terms categories={categories} /&gt;
              &lt;/Route&gt;
              &lt;Route exact path=&quot;/privacy&quot;&gt;
                &lt;Privacy categories={categories} /&gt;
              &lt;/Route&gt;
              &lt;Route exact path=&quot;/returns&quot;&gt;
                &lt;Returns categories={categories} /&gt;
              &lt;/Route&gt;
              &lt;Route exact path=&quot;/about&quot;&gt;
                &lt;About categories={categories} /&gt;
              &lt;/Route&gt;
              &lt;Route path=&quot;/sitemap.xml&quot; onEnter={reload}/&gt;
              &lt;Route path=&quot;/robots.txt&quot; onEnter={reload}/&gt;
              &lt;Route exact path=&quot;/:catSlug&quot;&gt;
                &lt;ProductsList categories={categories} products={products} userCountry={userCountry}/&gt;
              &lt;/Route&gt;
              &lt;Route exact path=&quot;/:catSlug/:productSlug&quot;&gt;
                &lt;Product alertIsVisble={() =&gt; dispatch(allActions.showAlert())} categories={categories} products={products} userCountry={userCountry} /&gt;
              &lt;/Route&gt;
              &lt;Route&gt;
                &lt;NotFound categories={categories} /&gt;
              &lt;/Route&gt;
            &lt;/Switch&gt;
  </code></pre>