组件内导航守卫会出现无法拦截$router.go(-1)或者物理返回按钮,在拦截函数外包裹setTimeout即可。具体原因还未发现。
setTimeout(() => {
this.$confirm('编辑的页面布局尚未保存,确定离开?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
next()
return
}).catch(() => {
this.$message({
type: 'info',
message: '已取消'
})
next(false)
return
})
}, 500)