Nuxt · NUXT0107

Guard global middleware redirects against the target route

Flags a global route middleware that redirects to a fixed route without checking where navigation is going.
NUXT0107vite-doctor/nuxtroutingerrorSuggestion

Run this rule

pnpm nuxt doctor --rules nuxt/routing/no-global-middleware-redirect-loop

Why it matters

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.

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')
})
Copyright © 2026