How to realize js Jump Page by react-route4

1. Due to the needs of the business scenario, the route jump is controlled through js, and there is no programmatic route navigation

in the react-router4 documents.

https://codeshelper.com/q/10.

I found this article on the website, but I can only get the history objects in props in the App component, but I can"t get the sub-components and sub-components under App. I don"t know if I"m missing something, or if I have the wrong configuration.

below is my route and index.js configuration

clipboard.png

clipboard.png

there is another way to achieve it through withRouter, but this method will make it more complex for my components to get through ref, so I would like to ask if there is a simpler method or case.

Aug.07,2021

return < Redirect to= {'/'} / > try something like this. I don't quite understand what you mean.


Route components can use props render to specify components, so you can inject history into each routing component, which is only for each routing component, and future components can only be delivered layer by layer. If you need to provide history for each component at the same time, you can use context API, or external introduction. But personally, I think the way of injection is more in line with the idea of React.

Menu