Angular lazy loading mechanism refresh after refreshing the quick fix method _angularjs

Source: Internet
Author: User
Tags rollback

Today in the project encountered a very strange problem, the use of oclazyload lazy load angular module, refresh the page, click the rollback button can not return to the previous page. It is estimated that the lazy loading mechanism destroys the State association within the angular, resulting in the inability to return to the previous state (Click the rollback button Ui-routre $stateChangeStart event will not be triggered), of course, this is only a guess, because the incident relationship did not go into depth to explore the source code.

Solution for angular lazy loading mechanism that cannot be rolled back after refreshing:

By looking at the angular (ionic) source, $browser has a Onurlchange method on this service, and when we change the URL address from outside of the angular, we call the event handler that is registered in this method, as shown in the following figure:

In this case, you can register a function at the program entry

When you jump to state through the browser fallback/forward button, the page is reloaded, and if you use System state, it will not go into this method 
$browser. Onurlchange (function (URL) { 
//todo Parsing the state in the URL, using lazy load to load the state module, implementation page Refresh
};

This function allows you to refresh the page again when you go back and forward ...

The above is a small set to introduce the angular lazy loading mechanism refresh can not be returned after the rapid solution, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.