mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
fix(nuxt): allow validate
return typing to be either error or boolean (#22323)
This commit is contained in:
parent
6f365313c4
commit
03fbd30d1c
@ -14,7 +14,7 @@ export interface PageMeta {
|
|||||||
* statusCode/statusMessage to respond immediately with an error (other matches
|
* statusCode/statusMessage to respond immediately with an error (other matches
|
||||||
* will not be checked).
|
* 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
|
* Where to redirect if the route is directly matched. The redirection happens
|
||||||
* before any navigation guard and triggers a new navigation with the new
|
* before any navigation guard and triggers a new navigation with the new
|
||||||
|
15
test/fixtures/basic-types/types.ts
vendored
15
test/fixtures/basic-types/types.ts
vendored
@ -116,6 +116,21 @@ describe('middleware', () => {
|
|||||||
abortNavigation(true)
|
abortNavigation(true)
|
||||||
}, { global: 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', () => {
|
describe('typed router integration', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user