How to solve the problem of invalidation after addRoutes refresh?

for example, use addRoutes to control routing permissions. If there is no problem with the normal operation of login point menu route blocking, add is very ok,. The problem with add is that router is restored to the initial data as soon as you refresh the page. I tried to addRoutes, again after refreshing, but there was no effect. It was still a blank. Although I don"t understand why reason is added in router.beforeEach, I don"t understand why it doesn"t work. Part of the code is as follows

.
appRouter.beforeEach((to, from, next) => {
    if (to.matched.length === 0) {
        next({ path: "notFound" })
    } else {
        if (to.path === "/login") {
            if (getToken()) {
                next({ path: "/" })
            } else {
                next()
            }
        } else {
            if (getToken()) {
                if (appStore.getters.role.length === 0) {
                    commonApi.getUserInfo().then(({data: {resultCode, result, msg}}) => {
                        appStore.dispatch("setRoleRouter", result.role).then((res) => {
                            appRouter.addRoutes(res)
                            next()
                        })
                    })
                } else {
                    next()
                }
            } else {
                next({ path: "/login" })
            }
        }
    }
})

ask for the boss"s answer

Mar.06,2021

see if it's a redirect problem. Page 404 is placed at the bottom of the asynchronous route!


how did brother dei solve it?


refer to examples on the Internet. They all write like this, saying no problem, but none of them take effect. Finally, change next () to next (to) to jump again, take effect, and solve the problem

.
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-1b35c1d-2b737.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-1b35c1d-2b737.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?