fix(nuxt): allow validate return typing to be either error or boolean (#22323)

This commit is contained in:
Daniel Roe 2023-07-25 17:09:41 +01:00 committed by GitHub
parent 6f365313c4
commit 03fbd30d1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -14,7 +14,7 @@ export interface PageMeta {
* statusCode/statusMessage to respond immediately with an error (other matches
* will not be checked).
*/
validate?: (route: RouteLocationNormalized) => boolean | Promise<boolean> | Partial<NuxtError> | Promise<Partial<NuxtError>>
validate?: (route: RouteLocationNormalized) => boolean | Partial<NuxtError> | Promise<boolean | Partial<NuxtError>>
/**
* Where to redirect if the route is directly matched. The redirection happens
* before any navigation guard and triggers a new navigation with the new

View File

@ -116,6 +116,21 @@ describe('middleware', () => {
abortNavigation(true)
}, { global: true })
})
it('handles return types of validate', () => {
definePageMeta({
validate: async () => {
await new Promise(resolve => setTimeout(resolve, 1000))
// eslint-disable-next-line
if (0) {
return createError({
statusCode: 404,
statusMessage: 'resource-type-not-found'
})
}
return true
}
})
})
})
describe('typed router integration', () => {