SPA single page application.

Source: Internet
Author: User

See this problem, the first to say their own understanding of the extent, and then refer to the amendment, to strive to understand this time to find out

Own understanding: Single-page application, to solve the embarrassment of the browser to get Data refresh page, through the AJAX request data to reach the asynchronous update view of the button, the principle of implementation by two kinds,

First, through the change of the hash value, the callback function of binding onhashchange updates the view, because the change of the hash value will not cause the page to lose its response and will not send the request to the server. The following is a list of several possible ways to change the hash value, changing the hash in the URL. The browser fallback button may appear in the history of the URL contains a hash value is not the same, will trigger the event, as well as trigger with turtle Point of the link changes, and then through the JS directly get Location.hash to change the resulting event trigger.

Second, add records to the browser's history stack by using the same H5 Historyapi. The past method only achieves forward and backward and jumps by Back,forward,go three methods. To H5 more Pushstate,replacestate method. Pushstate is simply added and does not jump to that record, while replacestate, the length of the entire history of the replacement record does not change. Hitstory.pushstate (Data,title,url), writes the first parameter data to the URL and specifies the value of the title. A record is added to the history stack by executing a popstate event where popstate is used to listen to changes in history, which can be understood as listening to the browser back and forth. Executes Location.reload () after binding the Onpopstate event; History.js is used for patching because of compatibility issues.

SPA single page application.

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.