The principle and difference between Vue hash routing and history routing

The difference between hash routing and history routing

Reason: A major feature of SPA single-page applications is the front-end routing. The front-end directly controls the routing jump logic instead of the back-end personnel, thus giving the front-end more freedom.
1. There is # in the address bar of hash routing, but there is no histoy routing.
2. The compatibility of hash routing is better. History routing is launched after HTML5.
3. The principle of hash routing , when the hash value changes, it will not be sent to the server Instead, the request will trigger the onhashchange event to modify the page content based on the hash value.
4. The principle of history routing is to use window.history related APIs to achieve routing jumps, thereby changing the content of the page. Since the routing jump is performed through the history API, no request is made to the server, which also achieves the purpose of front-end routing.
5. The history needs the cooperation of the backend, otherwise the page will be refreshed, or a 404 error will be reported according to the path access, because the packaged file generally only has an index.html file and some packaged js files and folders, so the backend needs to be restarted Directed to the home page, enter the project, and then configure the routing.

Guess you like

Origin blog.csdn.net/qq_37489791/article/details/130519653