Hash pattern

The idea behind hash mode is the onHashChange event, which you can listen for on the window object and use the HASH of the URL to simulate a full URL, so that when the URL changes, the page doesn't reload. window.onhashchange = function(e){ console.log(e.oldURL, e.newURL); let hash = location.hash.slice(1); console.log(hash); //red document.body.style.color = hash; }Copy the code

Disadvantages of history: In hash mode, the front end route modifs the information in #, and the browser does not play with it when requesting it, so no problem. Under History, however, you are free to change the path, and if there is no response or resource on the server, a 404 will spawn every minute. Some configuration is required (backend configuration is available on the Vue website)

The history mode

PushState API to complete the jump without reloading the page history.go(-2); // Back twice history.go(2); // forward twice history.back(); / / back hsitory. Forward (); / / to go forwardCopy the code