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.
nuxt/routing/no-global-middleware-redirect-loopsrc/rule-packs/nuxt/rules/nuxt/no-global-middleware-redirect-loop.ts Upstream docs 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.
Recommended fix
Return early when to.path (or to.meta) already matches the target, or move the redirect into named middleware.
Useful links
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')
})