javascript - Why can hash be used for route jumps but not refresh the page?
过去多啦不再A梦
2017-06-13 09:24:20
What is the principle of hash
This is not about the principle of implementing hash routing. I know how to implement it. What I want to know is why hash can be done
Just follow the http protocol...
The principle is that the modification of the hash will not cause the browser to refresh. This is the most fundamental reason. If there are other attributes modified on the URL, it will not cause a refresh. It can also be used for routing. It’s that simple
This is originally the anchor information within the page, used for jumping within the page, such as Baidu Encyclopedia. The content behind the link description
# represents the id of the anchor point. When this information exists, it will jump to the anchor point specified on the page. If you look at the Dom structure, you can see the following
ps://wapbaike.baidu.com/item/http/243074?adapt=1&fr=aladdin#u0
It started out as an anchor point and was used as a non-refresh jump
The advantage of this is that it can implement front-end routing, refer to /a/11... As for why it can be achieved, it is because the internal design of the browser is like this. Modify the hash and the browser will not jump.