Having trouble protecting child routes from parent routes, facing some issues
export default new Router({
routes: [
//frontend routes
{
{path: 'auth', component: Auth, children: authroutes,
beforeEnter: (to, from, next) => {
// check if user is a guest or loggedin
auth.canAccess(permissions.is_guest)
.then((res) => {
if (res.data.status) {
next();
} else {
router.push('/auth/not-allowed');
}
})
}}
]
}
]
})
Currently dealing with child routes
authroutes.js
const authroutes = [
{path: '', redirect: 'login'},
{path: 'login', component: Login, name: "login" },
];
Applying the above beforeenter function to child routes works but causes code repetition
Seeking a way to protect children from the parent route
For example: protect /auth/login and /auth/register