Vue Router rejects a guard that takes next but never calls it
Fix it fast
Most common cause, 1 of 2An async guard declares next and returns early
Drop the next parameter and return the outcome from every branch.
router.beforeEach(async (to) => {
if (to.name !== 'Login' && !(await isLoggedIn())) {
return { name: 'Login' }
}
})Short answer
Vue Router throws "Error: Invalid navigation guard" in development when a guard declares the third next parameter but finishes without calling it: an async guard that returns early, or a plain guard that returns a value. Remove next and return true, false or a route location instead. Applies to Vue Router 4.6 and 5.5; 5.0.3+ also deprecates next.
Which cause do you have?
Find every guard that still has three parameters. The check only runs when a guard's function length is above 2, so any guard listed here is a suspect; a guard with two parameters cannot raise this error.
grep -rnE "(beforeEach|beforeResolve|beforeEnter|beforeRouteEnter|beforeRouteUpdate|beforeRouteLeave)[^)]*next" srcThen find the line you see in this list and open its fix:
- 1An async guard declares next and returns early
The guard is async (or returns a Promise) and one branch ends with return, await or nothing, without reaching next() - 2A plain guard returns a value but also declares next
The guard is not async, it has a return false, return '/login' or return true, and next sits unused in its parameter list
What does the error look like?
Error: Invalid navigation guard[VUE_ROUTER_R0023] The "next" callback was never called inside ofIf you are returning a value instead of calling "next", make sure to remove the "next" parameter from your function.
Cause 1 of 2
An async guard declares next and returns early
You seeThe guard is async (or returns a Promise) and one branch ends with return, await or nothing, without reaching next()
Check
Vue Router throws Invalid navigation guard after an async guard's Promise settles if the guard declared next and never called it. The router decides this from the function's parameter count, so an async (to, from, next) guard that resolves on any branch without next() fails even when that branch returned a sensible value.
// fails: next is declared, the early branch never calls it
router.beforeEach(async (to, from, next) => {
if (!(await isLoggedIn())) return { name: 'Login' }
next()
})Fix
Drop the next parameter and return the outcome from every branch. Returning nothing or true lets the navigation continue; returning a location redirects.
router.beforeEach(async (to) => {
if (to.name !== 'Login' && !(await isLoggedIn())) {
return { name: 'Login' }
}
})Verify
Navigation reaches the target or the login page, and the console no longer shows the never-called warning.
grep -rn "async (to, from, next)" srcConfirmed by raw.githubusercontent.com
Cause 2 of 2
A plain guard returns a value but also declares next
You seeThe guard is not async, it has a return false, return '/login' or return true, and next sits unused in its parameter list
Check
For a non-async guard the router accepts a returned value only when the guard has two parameters. With next present, any return other than undefined, without a next() call first, rejects the navigation with Invalid navigation guard. The Vue Router guide says that as long as a guard declares next, it expects next to be called.
// fails: returns a value, next is never used
router.beforeEach((to, from, next) => {
if (!auth.user) return '/login'
return true
})Fix
Use one style per guard. The current guide maps next() to return, next(false) to return false and next('/login') to return '/login'. If you must keep next for now, call it exactly once on every path and return nothing.
router.beforeEach((to) => {
if (!auth.user && to.path !== '/login') return '/login'
})Verify
Run the app in dev mode and trigger the redirect; the route changes without a rejected navigation in the console.
npm run devConfirmed by router.vuejs.org
How do I stop it coming back?
- Write new guards with two parameters only; on Vue Router 5 any call to next already logs a deprecation warning in development.
- Add the grep from the first step to CI so a three-parameter guard cannot land unnoticed.
- Exercise the redirect branch of each guard in a dev build: production bundles drop the check, so the same mistake there shows up only as a navigation that never finishes.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.