我寫(xiě)的是vue 單頁(yè)應(yīng)用 a>b>c 登錄成功后 顯示d頁(yè)面 我 想實(shí)現(xiàn)d頁(yè)面瀏覽器后退按鈕失效 請(qǐng)問(wèn)怎么實(shí)現(xiàn) 查了些用路由的全局鉤子 我現(xiàn)在用的是router hash模式
可以用router.replace(location) 它不會(huì)向 history 添加新記錄,替換掉當(dāng)前的 history 記錄。
案例鏈接
//replace
<router-link to="/D" replace>Go to D</router-link>
or
router.replace('D')
用組件內(nèi)的鉤子。
beforeRouteEnter (to, from, next) {
next(vm => {
// 通過(guò) `vm` 訪問(wèn)組件實(shí)例
})
}
你可以在
beforeRouteLeave
中直接訪問(wèn)this
。這個(gè)leave
鉤子通常用來(lái)禁止用戶在還未保存修改前突然離開(kāi)??梢酝ㄟ^(guò)next(false)
來(lái)取消導(dǎo)航。
來(lái)自文檔: https://router.vuejs.org/zh-c...