I have this specific case where if the user routes to say topics/rendering, I need to show him a seperate Component and when user routes to topics/10, I need to show him another Component. The problem I am facing right now is that even when I do topics/rendering, I see both of the components being rendered on screen. Also when user routes to topics/math/10, I need to route him to a different page.
Here is the routing part in my App.js (default App.js)
<div className="App">
<Router>
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
<Route exact path="/topics" component={Topics} />
<Route exact path ="/topics/rendering" component={Description}/>
<Route exact path="/topics/:id" component={Topic} />
<Route path="/topics/:description/:id" component={TopicExtended}/>
</Router>
</div>
You want to wrap the Route
components in a Switch
component so that only one of them will be rendered at a time.
<div className="App">
<Router>
<Switch>
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
<Route path="/topics" component={Topics} />
<Route path="/topics/rendering" component={Description} />
<Route path="/topics/:id" component={Topic} />
<Route path="/topics/:description/:id" component={TopicExtended} />
</Switch>
</Router>
</div>
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