一、 编程式导航
![vue router](https://static.blogweb.cn/article/c62d53af42d24c95b5740ff9e9526e39.webp)
![vue router](https://static.blogweb.cn/article/3ac328d8ea0148bbb529b7bac245bbc4.webp)
二、路由守卫
beforeRouteEnter(to: any, from: any, next: any) {
const obj = localStorage.supervisionUserInfo
? JSON.parse(localStorage.supervisionUserInfo)
: {}
const { auditStatus } = obj
if (auditStatus !== 1) {
next('/limit')
return
}
next()
}
beforeRouteEnter(to: any, from: any, next: any) {
API.getAuditStatus(this, {})
.then((res: any) => {
const { auditStatus } = res.data
localStorage.setItem(
'supervisionUserInfo',
JSON.stringify({ ...res.data })
)
if (auditStatus === 1) {
next('/')
} else {
next()
}
})
.catch(() => {
next()
})
}