Here is my two Route and when I am navigate to /blogs/new BlogsShow Component also running. How to prevent that.
<Route path="/blogs/new" component={BlogsNew} />
<Route path="/blogs/:id" component={BlogsShow} />
Wrap those two routes in a <Switch>
component and the first one that matches will render exclusively.
For example something like this:
import { Switch, Route } from 'react-router-dom';
// ...code
<Switch>
<Route path="/blogs/new" component={BlogsNew} />
<Route path="/blogs/:id" component={BlogsShow} />
</Switch>
For more details see their documentation.
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