router: onpopstate

learning mark

 

history.pushState(stateObject, title, url);

tip: stateObject = {key: value, ...}, must be serializable, understood as JSON.stringify & JSON.parse

 

The received urlparameter is the stringtype, which is used to change the url of the current address bar.

One thing to note is that this parameter cannot be the same as cross-domain, that is, the protocol, domain name, and port must be the same

 

replaceStateThe received parameters are the pushStatesame, but the final effect is: the address bar url will change according to the received parameters, but the browser does not add the browser's history to the current browsing history stack, but replaces the current browser's history.

 

Through pushStateand replaceStatecan change the URL, but will not actively trigger the browser reload.

 

Note: javascript scripts executing window.history.pushState and window.history.replaceState will not trigger onpopstate .

 

Note: There are differences in how different browsers handle popstateevents when a page is loaded. Chrome and Safari usually emit ( emit  ) popstatethe event when the page loads, but Firefox doesn't , so it may be necessary to call it manually once

 

Note that the pushState() method does not cause the hashchange time to occur, even if the old and new urls are only hashed differently.

 

https://developer.mozilla.org/zh-CN/docs/Web/Events/popstate

 

https://segmentfault.com/a/1190000007166839

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326467215&siteId=291194637