routing

 

In a traditional website composed of multiple pages, there is no need for routing. At that time, jumping (navigation) through links can meet the needs. However, with the development of Ajax and the mobile Internet, there are more and more single-page applications. There is no problem in simulating multi-page switching in a single page ( opening a page through 1 URL), but the problem is how to construct a "page switching" that can realize "page switching" through URL and this URL must also meet the requirements of linkable, bookmarkable, and shareable Characterization becomes a difficult technical problem. The mature solution now is to use the change of the hash fragment in the url to trigger the "page switch". This mechanism that maps the url (hash fragment) and the "page" is called a router . The key in routing The technology is to monitor the changes of the url (hash fragment). Browsers that support the hashchange event can easily do this. Browsers that do not support the hashchange event usually need to use setInterval to poll for changes in the url at a frequency of about 100ms/time. Many application frameworks support routing, such as Backbone and Angular (in addition to ngRouter , uiRouter supports more powerful functions), and there are many independent script libraries that support routing functions, such as router.js, director.js, etc.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325518938&siteId=291194637