[Vuejs]-Vue Router – Invalid navigation guard error

1👍

Actually the issue is the fact that not all paths of your navigation guard call next()

All of your code is wrapped in a single if statement. If that first if statement is not true, then vue-router doesn’t know what to do.

router.beforeEach(...) {
  if (to.matched...) {
    if(user) {
      next()
    } else {
      next('/about')
    }
  }
  // Error here
}

These types of mistakes are exactly why using next is not really recommended and is only optionally supported at this point in vue-router 4.

The fix however is quite simple. Outside of that first if statement, the very last line of code should be another call to next()

👤yoduh

Leave a comment