[Vuejs]-How to redirect on other route if condition is true in in router.js vuejs

0👍

So the reason why you have this error is because each time Vue router tries to switch to a new route you tell it to switch to a new route again.

The solution would be to let Vue Router do it’s work when you reach the desired destination.

if (Object.keys(store.state.AppActiveUser).length !== 0 && !store.state.AppActiveUser.is_customer ) {
        var am_i_there_yet = to.name == 'dashboard';
        if (!to.meta.authRequired && auth.isAuthenticated() && !am_i_there_yet) {
            router.push({ path: '/dashboard', name: 'dashboard', component: './views/DashboardAnalytics.vue' })
        }

    } if (Object.keys(store.state.AppActiveUser).length !== 0 && store.state.AppActiveUser.is_customer) {
        var am_i_there_yet = to.name == 'customer-dashboard';

        if (!to.meta.authRequired && auth.isAuthenticated() && !am_i_there_yet) {
            router.push({ path: '/customer/dashboard', name: 'customer-dashboard', component: '@/views/apps/customerComponents/dashboard/DashboardAnalytics.vue' })
        }
    }

This is a related question that solves the same problem: Why am I getting the error Maximum call stack size exceeded in Vue Router?

Leave a comment