What is the setting of the routing guard in vue?

I have a parent route in the vue-cli project, and there are several child routes below. As shown in the following figure

now I want to set up the route guard, is the entire route set must be judged by the same condition, the route guard can only write on it? I want to write it only once, not to set up each child route separately.

Mar.12,2021

router.beforeEach((to, from, next) => {
    if(to.path=='/xxxx'){    
        xxxxxx;
        next()
    }
}

asked the bigwigs in WeChat group.
you can do this as a global guard, first write the name that needs to be routed into an array, and then use the to.name method to determine.


your way of writing should be vue-router. There are three common formats of routing guards in vue-router:

1) Global routing guard

such as beforeEach, afterEach

2) Route exclusive guard

such as beforeEnter

3) component exclusive guard

such as beforeRouterEnter, beforeRouterUpdate, beforeRouterLeave

their application scenarios are different, and your question is too broad, so it's possible.

Menu