Skip to content Skip to sidebar Skip to footer

React-router-4 Routing From Another Component

Is it possible to route a component from another component? So normally it would be done like below link

Solution 1:

That's definitely possible and your example should even work as is. The biggest thing you'll need to make sure of is that your <Route>s were rendered as some point. The reason your example works is because you're rendering <Nav> in the same render() method as your <Switch> statement. If you were to instead just render <Nav> without ever rendering the switch statement, then the NavLinks would take you somewhere that React Router hasn't been informed about. That's typically why your <Route>s are almost always in your most parent component, to make sure they're rendered.


Post a Comment for "React-router-4 Routing From Another Component"