1、路由变换
(1)应用hash
获取url中的hash:http://www.bbbb.com#hashstr
`window.location.hash //#hashstr`
* 1
扭转hash:
`window.location.hash = "#hahah";
// 变成http://www.bbbb.com#hahah`
* 1
* 2
最重要的是hashchange事件,通过这个事件来写页面跳转等的业务逻辑,每当url的hash扭转都会触发这个事件
window.addEventListener("hashchange", function() {
// 获取hash值
var hash = window.location.hash;
// 依据获取的hash做相应的操作
. . .
});
(2)HTML5 history api
history.pushState(stateObject, title, url)
history.replaceState(stateObject, title, url)
window.onpopstate事件
发表回复