How does the routing guard of vue-router jump to route?

I want to use vue-router "s navigation guard to define a global guard to listen for changes in routing
to implement a function that intercepts entry to the page, and then jumps to the login page
but what I write is always wrong. I can"t find a solution after Google. Please tell me how to do
error message:

clipboard.png

:

clipboard.png

ask for help, thank you very much!


clipboard.png


next({ path: '/login', replace: true })

should be possible


there is an endless loop. BeforeEach means that accessing all routes will execute next ('/ login'), visit / login execute next ('/ login') and then visit / login execute next ('/ login') and access / login execute next ('/ login'). It can be judged that next ('/ login')


endless loop can be executed when from.name is not login.
next ('/ login') can be understood as redirecting to / login.
so you will also enter the hook function, and when you judge again, you will also enter the if branch.

Menu