What is client-side routing and how is it used?

点点圈 提交于 2019-12-18 10:44:53

问题


I will be glad if someone could answer the following questions

  1. How does it work?
  2. Why is it necessary?
  3. What does it improve?

回答1:


Client side routing is the same as server side routing, but it's ran in the browser.

In a typical web application you have several pages which map into different URLs, and each of the pages has some logic and a template which is then rendered.

Client-side routing simply runs this process in the browser, using JavaScript for the logic and some JS based template engine or other such approaches to render the pages.

Typically it's used in single page applications, where the server-side code is primarily used to provide a RESTful API the client-side code uses via Ajax.




回答2:


I was trying to build a Single page application and came to know about client side routing.

By implementing client side routing I was able to achieve the following

  1. The front and back buttons in the browser started working for my single page JavaScript application. This was very important while accessing the page from a mobile browser.
  2. The user was able to Bookmark/share a URL which was not possible earlier.


来源:https://stackoverflow.com/questions/10190215/what-is-client-side-routing-and-how-is-it-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!