Nuxt · Routing
NUXT0107Guard global middleware redirects against the target route
Flags a global route middleware that redirects to a fixed route without checking where navigation is going.
vite-doctor/nuxtroutingerrorSuggestion
Why it happens
Nuxt runs global middleware on the route it redirects to. Doctor reports a fixed redirect that the middleware reaches again on that route, and skips conditions and arguments that depend on mutable state or other values it cannot establish.
Fix
Return early when to.path (or to.meta) already matches the target, or move the redirect into named middleware.
Example
Skip the redirect on its target
Before
// app/middleware/auth.global.ts
export default defineNuxtRouteMiddleware(() => {
return navigateTo('/login')
})
After
// app/middleware/auth.global.ts
export default defineNuxtRouteMiddleware((to) => {
if (to.path !== '/login') return navigateTo('/login')
})
Verify the fix
Run only this rule after editing so the report stays focused on the diagnostic you are closing:
pnpm nuxt doctor --rules nuxt/routing/no-global-middleware-redirect-loop