Vue Navigation Guards
up:: Vue Methods that automatically get called by Vue Router.
Coming to a page
beforeEach (global)
In main.js
.
to
: where you are goingfrom
: where you came fromnext()
: confirm or cancel- or pass in a string/direction object where to redirect the user to
- Warning: This triggers on each re-route, means that you can create an infinite loop if you don’t add an if statement.
beforeEnter (page)
Add this on the Vue Router configuration object.
Or in the component config object:
afterEach (global)
Runs after a navigation has happened. It has no next
param. But you could use it for analytics.
Leaving a page
beforeRouteLeave
Called before the entering on a site guards.
Handy to give users a warning before leaving with unsaved changes.