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