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.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e53869-4524f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e53869-4524f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?