recently, many problems have been encountered in the process of transforming vue with Nuxt, such as route authentication in middleware, which is valid when the route address is changed, but refresh will not trigger how to solve it, and addRoutes is not defined here. The route of nuxt is automatically generated according to the path of the page folder. In the past, if vue wanted to change the routing address in the third-party plug-in, it only needed import router from"@ / router" to use router.push ({path:"xxx"}) in the third-party plug-in. Currently, redirect is used to modify the path in nuxt. How to modify this? The
code is as follows:
export default ({store,route,redirect}) = > {
let isNotFound = false
if (process.browser) {
if(!route.name) {
redirect( "/");
}
if (getToken()) {
if (store.getters.roles.length === 0) {
store.dispatch("GetInfo").then(res => {
const roles =[ res.data.type ]
store.dispatch("GenerateRoutes", { roles }).then(() => {
// router.addRoutes(store.getters.addRouters)
})
}).catch(error=>{
store.dispatch("LogOut")
})
}
} else {
if (!isNotFound) {
store.dispatch("NotFoundRoutes").then(() => {
isNotFound = true
redirect("/login/index")
})
}
}
}
}