March 2018
Beginner to intermediate
344 pages
7h 7m
English
We can use router.beforeEach to listen for routing events globally across the application. This is worth using if you have authentication checks or other pieces of functionality that should be used in every route.
Here's an example that simply logs out the route the user is going to and coming from. Each one of the following examples assume that the router exists in scope similar to the following:
const router = new VueRouter({ routes})router.beforeEach((to, from, next) => { console.log(`Route to`, to) console.log(`Route from`, from) next();});
Once again, we have to call next() to trigger the next route guard.
Read now
Unlock full access