admin管理员组文章数量:1406052
Please help me to fix this
router.js
routes: [{
path: "",
ponent: () => import("@/layouts/full-page/FullPage.vue"),
children: [{
path: "/pages/login",
name: "page-login",
ponent: () => import("@/views/pages/Login.vue")
}, {
path: "/pages/signup",
name: "page-signup",
ponent: () => import("@/views/pages/Signup.vue")
}, {
path: "/pages/error-404",
name: "page-error-404",
ponent: () => import("@/views/pages/Error404.vue")
}]
}, {
path: "*",
redirect: "/pages/error-404"
}]
and
router.beforeEach((to, from, next) => {
if (to.path != "/pages/login") {
if (auth.isAuthenticated()) {
next();
} else {
if(to.path == "/pages/signup") {
next("/pages/signup");
}else{
next("/pages/login");
}
}
} else {
next();
}
});
When I open pages/login the error doesn't happen. But when I open pages/signup, it's always an error.
This is the error in the console:
"RangeError: Maximum call stack size exceeded"
Please help me to fix this
router.js
routes: [{
path: "",
ponent: () => import("@/layouts/full-page/FullPage.vue"),
children: [{
path: "/pages/login",
name: "page-login",
ponent: () => import("@/views/pages/Login.vue")
}, {
path: "/pages/signup",
name: "page-signup",
ponent: () => import("@/views/pages/Signup.vue")
}, {
path: "/pages/error-404",
name: "page-error-404",
ponent: () => import("@/views/pages/Error404.vue")
}]
}, {
path: "*",
redirect: "/pages/error-404"
}]
and
router.beforeEach((to, from, next) => {
if (to.path != "/pages/login") {
if (auth.isAuthenticated()) {
next();
} else {
if(to.path == "/pages/signup") {
next("/pages/signup");
}else{
next("/pages/login");
}
}
} else {
next();
}
});
When I open pages/login the error doesn't happen. But when I open pages/signup, it's always an error.
This is the error in the console:
Share Improve this question edited Apr 16, 2020 at 12:24 Dan 63.2k18 gold badges111 silver badges119 bronze badges asked Apr 16, 2020 at 10:48 resitdcresitdc 331 silver badge4 bronze badges"RangeError: Maximum call stack size exceeded"
1 Answer
Reset to default 5This will cause an infinite loop:
if(to.path == "/pages/signup") {
next("/pages/signup");
It's redirecting to the same route it's already going to, which causes the beforeEach
to run again, and then triggers another redirect on the next iteration. Change that to:
if(to.path == "/pages/signup") {
next();
本文标签: javascriptVueJS quotRangeError Maximum call stack size exceededquotStack Overflow
版权声明:本文标题:javascript - VueJS "RangeError: Maximum call stack size exceeded" - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744964708a2634873.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论