problem description
when I integrate the front and background of a project, the login page " http://localhost:8080/-sharp/Manage_Login/ "automatically jumps to" http://localhost:8080/-sharp/Index", and then I don"t use routing redirection. Later, I found that router.beforeEach triggered it twice. Why
the environmental background of the problems and what methods you have tried
related codes
router.beforeEach((to, from, next) => {
var data = JSON.parse(localStorage.getItem("key"));
console.log("to", to,"from", from)
if (to.matched.some(r => r.meta.requireAuth)) {
if (data) {
next();
} else {
var state = localStorage.getItem("state");
//
if (state === 0) {
next({
path: "/ErrorPage/!"
// query: {redirect: to.fullPath}
})
} else {
next({
path: "/Login",
query: {
redirect: to.fullPath
}
})
}
}
} else {
console.log(1)
next();
}
/* title */
if (to.meta.title) {
document.title = to.meta.title
}
console.log(2)
// next()
})
< H1 > triggered router.beforeEach twice < / H1 >