Catchall in a React Router Switch
Today we built a 404 page for a React app using React Router, via a Switch
statement with no specified path. Like a default clause, it catches if none of the other routes match:
<Switch>
<Route path="/about" component={About}/>
<Route component={NoMatch}/>
</Switch>
On any other path besides /about
, we'll render our NoMatch
component.