[Vuejs]-How do I use navigation guards in Vue.js?

0👍

beforeRouteEnter doesn’t have access to this. You would have to use a function that is defined outside of the object scope and call the function before next. The argument passed to next is the your vue component object so that you can set the properties of the component.

Something like this will work:

beforeRouteEnter (to, from, next) {
  axios.get('/service').then(res => {
    next(vm => {
      vm.res = res
    })
  }).catch(err => {
    next(vm => {
      vm.err = err
    })
  })
}

Leave a comment