mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-21 21:25:11 +00:00
fix(nuxt): ensure middleware is processed when returning true
(#22905)
This commit is contained in:
parent
1f98f34c8e
commit
2d46971162
@ -58,7 +58,7 @@ function getRouteFromPath (fullPath: string | Partial<Route>) {
|
||||
}
|
||||
}
|
||||
|
||||
type RouteGuardReturn = void | Error | string | false
|
||||
type RouteGuardReturn = void | Error | string | boolean
|
||||
|
||||
interface RouteGuard {
|
||||
(to: Route, from: Route): RouteGuardReturn | Promise<RouteGuardReturn>
|
||||
@ -130,7 +130,7 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({
|
||||
// Cancel navigation
|
||||
if (result === false || result instanceof Error) { return }
|
||||
// Redirect
|
||||
if (result) { return handleNavigation(result, true) }
|
||||
if (typeof result === 'string' && result.length) { return handleNavigation(result, true) }
|
||||
}
|
||||
|
||||
for (const handler of hooks['resolve:before']) {
|
||||
@ -250,6 +250,7 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({
|
||||
return nuxtApp.runWithContext(() => showError(error))
|
||||
}
|
||||
}
|
||||
if (result === true) { continue }
|
||||
if (result || result === false) { return result }
|
||||
}
|
||||
}
|
||||
|
@ -179,6 +179,7 @@ const plugin: Plugin<{ router: Router }> = defineNuxtPlugin({
|
||||
}
|
||||
}
|
||||
|
||||
if (result === true) { continue }
|
||||
if (result || result === false) {
|
||||
return result
|
||||
}
|
||||
|
@ -4,4 +4,5 @@ export default defineNuxtRouteMiddleware((to) => {
|
||||
statusCode: 401
|
||||
})
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user