How it works…

The beforeRouteEnter hook takes three parameters:

  • to: This is a Route object that represents the route requested by the user.
  • from: This is also a Route object that represents the current route. This is the route the user will be kept at in case of errors.
  • next: This is a function we can use when we are ready to go on with the switching of the route. Calling this function with false will prevent the route from being changed, and it is useful in case of errors.

When the preceding functions are called, we made a call with Axios to a web service that provided a string for a name and a string for a phone number.

When we are inside this hook, it's important to remember that we don't have access to this. It's because this hook runs ...

Get Vue.js 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.