Vue有兩種路由模式:hash,history
(1)hash模式
通過監聽路由的變化實現,如下代碼.路由中帶着#,變化的也都是#后面的值
window.onhashchange = function(event) {
console.log(event.oldURL, event.newURL);
let hash = loaction.hash //通過location對象來獲取hash地址
console.log(hash) // "#/notebooks/260827/list" 從#號開始
}
(2)history模式
url中沒有#,是全地址,所以刷新頁面的時候會根據全地址取請求后台,后台也需要做對應的處理,否則頁面請求不到就會404