Router.beforeEach

clipboard.png
clipboard.png

see that many blogs say that router.beforeEach, will be called again after calling next ("/ login") in router.beforeEach, but
! user=true and to.path!"/ login" do not call router.beforeEach, again after executing next ("/ login") for true, and next ("/ login") is still true in if condition, but if I change next ("/ login") to another route, there will be an endless loop call. Is it because of any change after the execution of next ("/ login")

Mar.12,2021

the logic you wrote above will be in an endless loop
after reading it for a long time, it feels like a sentence.

let user=xxxxxx
if(!user){
   next({ path: '/login' })
}else{
   next()
}

find out if the page you first opened is login,. If it is login, it will only be executed once

.
Menu