page not found in react router code example

Example 1: react router 404 redirect

<Route path='*' exact={true} component={My404Component} />
 // Or don't mention path
<Route component={My404Component} />

Example 2: react router catch all 404

<Switch>
   <Route path="/" exact component={Home}/>
   <Route path="/about" component={About}/>
   <Route component={Page404} />
</Switch>

Example 3: page not found on netlify with react router

*create _redirects file in your public folder
*add following content there -> /*    /index.html   200

Tags:

Misc Example