G
G
GrimJack2017-08-20 17:43:11
JavaScript
GrimJack, 2017-08-20 17:43:11

How to make a proper redirect from parent to child route?

There are routes:

const routes = [
    {
        path: '/dashboard',
        name: 'dashboard',
        component: dashboardMainPage,
        children: [
            {
                path: 'auth',
                name: 'dashboard.auth',
                component: dashboardAuthPage
            }
        ]
    }
];

const router = new VueRouter({
    mode: 'history',
    routes
});

The parent checks if the user is authorized:
created() {
            if(this.$store.getters.isLogged){
                //
            }
            else {
                this.$router.go({name: 'dashboard.auth'})
            }
        }

But this option cycles around in a circle
. How to do it right?
I tried to find some analogue of middleware in Laravel, but I did not find it for vue
PS
"vue": "2.4.2",
    "vuex": "^2.3.1",
    "vue-router": "^2.7.0"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GrimJack, 2017-08-20
@GrimJack

The question was that vue 2+ uses push instead of go

A
Artem0071, 2017-08-20
@Artem0071

It cycles because 'dashboard.auth' is in the 'dashboard' component
and it turns out that when entering 'dashboard' it redirects to 'dashboard.auth' which is in 'dashboard' which redirects to 'dashboard.auth' which is in 'dashboard' ' etc.
You just need to expand these components

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question