React-router Page left URL error

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.