In my index.js
, I have a render method with Router
that contains Route
s that show components:
<Router>
<div>
<Headers />
<ToggleSwitch />
<Route exact path="/" component={Home} />
<Route path="/library" component={Library} />
<Range />
</div>
</Router>
This works fine.
However, on the Library
route, I do not want to show either <Headers />
or <ToggleSwitch />
.
So I'd like to be able to apply the following approach, for example:
const isHeaderRoute = (!route.includes('library'))
{isHeaderRoute && (
<Headers />
<ToggleSwitch />
)}
To do this I would presumably need access to the URL path.
How can I achieve this using React Router?