了解vue-router原理中更新URL但不重載頁面的原理之一

window.onhashchange = function(e){

console.log(e);

}

總結:

location.hash與HTML5 history類似,都能夠在改變頁面的URL而不會引起瀏覽器的重載

但是location.hash支持比較早的瀏覽器,而history是在HTML5的新API,可能某些較早的瀏覽器不支持

因此在vue-router中對此做了兩種模式,即history模式與hash模式可以適應不同的瀏覽器

具體解釋之後更新vue-router的原理分析


分享到:


相關文章: