0

I am learning react and have a background in angular and have checked the docs and seen a tutorial about routing with react. In angular you can programatically route to components by geting an instance of the router and then calling

router.navigate(['/myroute'])

I feel like there has to be somthing similar in react, but have seen the docs and do not seen this. Ive just seen references to created a <Redirect /> component. I would much prefer to programatically route because I assumed one could do this when created a

<Switch><Route /> <Route /> ... etc </Switch>

So how does one programatically route to components in a similar way that one does with the above angular example?

Dan
  • 3,436
  • 11
  • 38
  • 65
  • 3
    Possible duplicate of [Programmatically navigate using react router V4](https://stackoverflow.com/questions/42123261/programmatically-navigate-using-react-router-v4) – The Reason Mar 21 '18 at 12:50
  • Possible duplicate of [Programmatically navigate using react router](https://stackoverflow.com/questions/31079081/programmatically-navigate-using-react-router) – Hinrich Mar 21 '18 at 13:48

1 Answers1

0

Check out option number 1 here: https://stackoverflow.com/a/42121109/5786795
That's exactly what you're looking for