Previous projects using react-router2.0, business-level pages to leave the time need to pop up their own pop-up box, according to the user's actions, whether can leave
Tried several ways have problems, not perfect, no way to users click the browser back support is very good, unless it is the default confirm display system, synchronous processing
1.setRouteLeaveHook
Setrouteleavehook No callback mechanism, can only modify the change flag, and then push again, but this is also problematic in the actual situation, because history has been push, with the user point back is not an interaction
2.onChange processing, onchange can be successful at the time, call callback, but the user click the browser back, in fact, there is no callback triggered, do not jump in the case, no way to recover the URL
In other cases, the page URL does not change,
A. May be a page jump, do not use hashhistory to operate, directly manipulate the native Location.history object
B. Page refresh test, hashhistory object length = 1, no address can be fallback
Online also have their own way to create a history, the project did not try to upgrade the project to react-router4.0 the time to solve the problem, the solution in fact has been stated in the previous article.
1.getUserConfirmation, when you create a history or define Hashrouter, set the confirmation popup, callback asynchronous processing
2. The page left through, the route changes when the prompt function Prompt component Https://reacttraining.com/react-router/core/api/Prompt implementation
A message can also be a way to see the actual project needs
3. Operation history requires the use of routed Histroy objects, the use of routed components and methods to jump, and not with the native location.history string
React-router Page left URL error