An endless cycle encountered in the use of beforeEach in vue;

when doing the vue project, I wrote the following code. The page is stuck and there is an endless loop. Maybe there is something wrong with the logic. The boss gives reason

.

related codes

mounted () {

console.log("aaa")
let _this = this
this.$router.beforeEach(function (to,from,next) {
  if(to.meta.auth) {
    if(window.localStorage.getItem("user")) {
      console.log("");
      next()
    } else {
      console.log("")
      console.log(_this.$router, "sfafasdfasdf")
      _this.$router.push({path:"/login"})
      next({
        path: to.path,
      })
    } 
  } else {
    console.log("");
    next({
      path: to.path
    })
  }
}) 

}

I want to log in and then jump to the page that the user wants to see before on the route where the guard is set

May.25,2021

you just log in all the time. You have to jump to log in when to.pathogenetic login account account log' and do not log in.







Menu