把當前頁面地址添加到緩存里,登錄成功后通過緩存獲取:
當前頁面添加👇
sessionStorage.setItem('returnUrl', window.location.href)
window.location.href = window.location.origin + '/login'
login頁面增加👇
if (sessionStorage.getItem('returnUrl')) { window.location.href = sessionStorage.getItem('returnUrl') } else { this.$router.push({ path: '/' }) // 如果緩存沒有 直接跳轉到默認路徑
}