0👍
✅
This is because when you logged out, auth.loggedIn()
will return false
.
So in redirect
property of login route, else
part execute. And you redirect to login page again, and then redirect
execute again and again. and in an infinite loop you are redirecting to login page.
You have to check and not run redirect function if you are redirecting to login page. You can use beforeEnter
like other routes:
function checkLogin(to, from, next) {
if (auth.loggedIn()) {
next({
path: "/dashboard",
});
} else {
next();
}
}
and in routes array:
routes: [
...
{
path: "/",
name: "login",
component: Login,
beforeEnter: checkLogin
},
...
]
Source:stackexchange.com