How to restrict users from accessing the login page again through address url/login after logging in in vue

// 
router.beforeEach((to, from, next) => {
  if (to.matched.some(record => record.meta.requiresAuth)) {
    if (!window.localStorage.token) {
      next({
        path: "/login",
      })
    } else {
      next()
    }
  } else {
    if(to.name == "Login" && !window.localStorage.token == false){
      next({
        path: "/",
      })
    }else{
      console.log("2");
      next()
    }
  }

tried to determine the page and status intercept, but when you enter enter manually, the page seems to refresh once, and it seems impossible to block it.

Apr.07,2021

sessionStorage find out, or judge whether the current session is valid on the login page. For example, send a packet to ask if you are logged in. If you are already logged in, go directly to router.push.

Menu