vue项目的登录跳转代码

router.beforeEach((to, from, next) => {
	if (to.matched.length === 0) {
		next('/error404')
	} else {
		if (!sessionStorage.getItem('sid')&&to.path!="/login") {
			next('/login')
		} else {
			next()
		}
	}
});

  一定要验证页面是不是login页面,否则会陷入进入login页面的死循环

posted @ 2020-07-22 18:30  只争朝夕,不负韶华  阅读(369)  评论(0)    收藏  举报