Vue: Redirected when going from “x“ to “x“ via a navigation guard
今天vue路由跳轉出現這個,百度一圈,各種設定都沒用,最後看了官方文檔,才明白還是***路由守衛***那裡沒跳轉明白,沖突了。
const LOGIN_PAGE_NAME = 'login'
router.beforeEach((to, from, next) => {
iView.LoadingBar.start()
const token = getSessionStorage('token')
if (!token && to.name !== LOGIN_PAGE_NAME) {
next({
name: LOGIN_PAGE_NAME // 跳轉到登入頁
})
} else if (!token && to.name === LOGIN_PAGE_NAME) {
next()
} else if (token && to.name === LOGIN_PAGE_NAME) {
// 已登入且要跳轉的頁面是登入頁
next()
} else {
next()
}
})
vue-router版本 : “vue-router”: “^3.0.1”,