102
rated 0 times
[
107]
[
5]
/ answers: 1 / hits: 9024
/ 3 Years ago, tue, february 2, 2021, 12:00:00
Here the router guard is working fine on my vue app, but after logging in, the following error appears on console.
Uncaught (in promise) Error: Redirected when going from "/login" to "/" via a navigation guard.
Here is my code snippet.
const routes = [
{
path: "/login",
component: () => import("../views/Auth/Login"),
meta: { hideForAuth: true },
},
{
path: "/",
component: DashboardLayout,
meta: { requiresAuth: true },
children: [
{
path: "home",
name: "Home",
component: () => import("../views/Home"),
},
],
},
];
The Auth guard:
const loggedIn = localStorage.getItem("auth");
router.beforeEach((to, from, next) => {
if (to.matched.some((record) => record.meta.requiresAuth)) {
if (!loggedIn) {
next({ path: "/login" });
} else {
next();
}
} else {
next();
}
if (to.matched.some((record) => record.meta.hideForAuth)) {
if (loggedIn) {
next({ path: "//" });
} else {
next();
}
} else {
next();
}
});
Can't figure out the problem. Thanks in advance !
More From » vue.js