The difference between vue front-end router routing hash and history mode

There are two ways to route vue-router, hash mode and history mode. Let’s briefly talk about the difference between the two.

model Popular explanation compatible principle
hash The # sign after the url tail and the following characters are all hash patterns. Compatible with IE8 and above Changes in the hash value will not cause the browser to send a request to the server, and the hash change will trigger the hashchange event (hashchange can only change the url fragment after #); although the hash path appears in the URL, it will not appear in the HTTP request. It has no impact on the backend at all, so changing the hash value will not reload the page. Basically, hash is used to implement front-end routing.
——————————————
Copyright statement: This article is an original article by CSDN blogger “The Laughing Little Universe” and follows the CC 4.0 BY-SA copyright agreement. Please attach the original source link for reprinting and this Statement.
Original link: https://blog.csdn.net/wangningjing87/article/details/100982120/
history history is not included# Compatible to IE10 and above The history mode URL must be consistent with the backend, so changing to history requires the cooperation of the backend, otherwise an error will be reported.
the difference

1. In hash mode, every time the page is refreshed, the thing after "#" is directly changed, and the address remains unchanged.

2. Every time the history is refreshed, it will re-request the entire URL from the backend, that is, re-request the server. If the backend does not respond in time, an error 404 will be reported! . The advantage of history is that you can modify the history record without immediately making a request to the backend.

3. However, if there are no hard standard requirements for the project, it is recommended to directly use the hash mode for development.

Guess you like

Origin blog.csdn.net/SYQ15544423296/article/details/132902885