React Router - BrowserHistory.Push VS. ContextTypes

I finish an advanced response / contraction tutorial and stumbled upon part of the course where the instructor uses browserHistory.push to reference the route, unlike the previous method used to create a static class variable called contextTypes and set it to something like React. PropTypes.blah blah blah.

What is the difference between this and using browserHistory.push? browserHistory.push seems a lot easier as a program redirection rather than setting context types.

Thanks!

+5
source share
1 answer

You do not know which textbooks you used, so this is a little shot in the dark.

I suppose you use something like https://github.com/reactjs/react-router-redux in your first tutorial, which synchronizes the state of the router with your reduction state and has the router in context. Then you can do something like:

this.context.router.push(location) to send the location change This will save the location change in your reduction state and then load this new route.

In the core of react-router-redux (and many other routing libraries) use https://github.com/ReactTraining/history to manage the history of routes moved to. This allows you to use the HTML5 history API in modern browsers, return to hashHistory (index.html / # page-one) or to memory history, that is, visualize the server side.

The story pack comes with its own API. And in your tutorial, that browserHistory.push() may directly call this history package API ( see here ).

This will cause the application to download a new route, but possibly turn off synchronization with your reductions repository.

In your second tutorial, reaction-router-reductions or other settings cannot be involved.

0
source

Source: https://habr.com/ru/post/1258785/


All Articles