Problems not triggered by refresh of Nuxt.js middleware

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")
      })
    }
  }

}

}

Apr.28,2021

because the code is executed as server-side code
add the judgment of the current service environment to the file

  const isClient = process.client;
    //
  if (isClient) {
    //
  }

to refresh the page in the client to trigger middleware, just set mode to spa, in nuxt.config.js. The default value is triggered on the server side, and the refresh page can be triggered on the client side after modification.
my project is feasible.


have you solved it? I have the same problem

Menu