Given I have 2 path rendering the same component, how do I avoid to repeat route configs like this :
<Route path="/path1" component={MyComp} />
<Route path="/path2" component={MyComp} />
Nested Routes Nesting Routes in React Router is pretty simple. All you need to do is create a new component to store your nested Routes this component should have a Routes component and inside that Routes component should be all the Route components that you are matching with the parent Route .
EDITED: Multiple routed with multiple layouts can be done by using <Outlet> component in layouts and <Route> component composition.
If the intention is to strictly match only /items , the <Route/> component accepts an exact prop. Adding this ensures that only the pathname that exactly matches the current location is rendered. Below is an example that uses the exact prop.
Best solution I found so far (but seems a bit strange) :
<Route path="/:path(path1|path2)" component={MyComp} />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With