In my App.js file, I have a few routes enclosed within the Switch. The components are rendered depending upon the route. However, there are some components that are always rendered irrespective of the route (wrapper and <Sidebar /> below).
// app.js
...
<Router>
<Switch>
<div class="wrapper">
<Sidebar />
<Route exact path="/" component={Home} />
<Route exact path="/about" component={About} />
</div>
<Route component={NotFound} />
</Switch>
</Router>
...
The problem is that the NotFound component is not being rendered because of wrapper and <Sidebar /> elements that are global on all routes. I have a couple of questions,
- How do I correctly show
NotFoundcomponent on invalid routes while keepingwrapperand<Sidebar />global? - Is keeping
wrapperand<Sidebar />global an anti-pattern? If so, how are global components rendered in routes?