(Vue: Redirected when going from “x“ to “x“ via a navigation guard
Vue: Redirected when going from “x“ to “x“ via a navigation guard今天vue路由跳转出现这个,百度一圈,各种设置都没用,最后看了官方文档,才明白还是***路由守卫***那里没跳转明白,冲突了。const LOGIN_PAGE_NAME = 'login'router.beforeEach((to, from, next) =>
·
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”,
更多推荐
已为社区贡献3条内容
所有评论(0)