How to block access to the router?

Want to block access to authorized users.

Wrote here such code.

router.beforeEach((to, from, next) => {
 const authUser = localStorage.getItem("auth");
 const profilePages = ["/profile"];
 const orderPaymnetPages = ["/order-payment"];
 const authRequired = !profilePages.includes(to.path);
 const authRequired2 = !orderPaymnetPages.includes(to.path);

 if (authRequired && authRequired2 && !authUser) {
next("/");
}
next();
});


But it throws an error RangeError: Maximum call stack size exceeded.

Need to blocked access routes /profile /order-payment

How can I fix it ?
April 4th 20 at 13:23
1 answer
April 4th 20 at 13:25
Solution
You have a circle work out the next("/");.
Add in if to.path !== '/'.

Find more questions by tags Vue.js