Vue routing modes (hash and history)

  For this type of progressive front-end development framework for Vue, in order to build SPA (single-page application), it is necessary to introduce front-end routing system, which is the meaning of existence Vue-router. Core front-end routes, --- is that while not changing the view request to the backend.

   1. In order to achieve this, the browser provides support for the following two:

       1, hash - that is, the URL address bar of the # symbol (this hsah not cryptology hash operation).

          For example, this URL: http: //www.abc.com/#/hello, hash value of # / hello. It is characterized by: hash Despite the URL, but will not be included in the HTTP request, there is no effect on the back end, thus changing the hash will not reload the page.

       2, history - in the use of new HTML5 History Interface to pushState () and replaceState () method. (Requires a specific browser support)

            These two methods used in the browser's history stations, currently available in the back, forward, foundation go on top, they provide functionality to modify history. Only when they perform the modification, although the change of the current URL, but your browser does not send an immediate request to the backend.

           history mode, there will be 404 cases, require background configuration.

    Second, the 404 error

          1, the hash mode, only the hash symbols before content is included in the request, such as http://www.abc.com, so the rear end, even if there is no route to achieve full coverage, will not returns a 404 error;

          2, the history mode, and the front end of the url must initiate a request to the url actual rear same as http://www.abc.com/book/id. If the backend lack of / book / id route processing, returns a 404 error. 

Guess you like

Origin www.cnblogs.com/huayang1995/p/12635424.html