底层实现原理
React 中基于history 实现的BrowserRouter, 通过 onpopstate事件和自定义的 onpushstate事件实现
代码:
的后退按钮
window.onpopstate = function (event) {
//console.log(event);
container.innerHTML...没有用到
// 参数三 跳转的路径
window.history.pushState({to},null,to)
}
// 覆写window.history.pushState方法
//...(state,title,url){
// 3.调用系统的该方法
pushState.call(window.history,state,title,url);
// 4.调用自定义的...onpushstate事件
window.onpushstate(state,title,url)
}
// 5.将事件定义在window属性上 浏览器的前进按钮
window.onpushstate