mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): don't short circuit middleware after validate function (#9180)
This commit is contained in:
parent
ba940719fe
commit
f4ba7ec82d
@ -1,12 +1,11 @@
|
||||
import { createError, defineNuxtRouteMiddleware } from '#app'
|
||||
import { defineNuxtRouteMiddleware } from '#app'
|
||||
|
||||
export default defineNuxtRouteMiddleware(async (to) => {
|
||||
if (!to.meta?.validate) { return }
|
||||
|
||||
const result = await Promise.resolve(to.meta.validate(to))
|
||||
if (typeof result === 'boolean') {
|
||||
return result
|
||||
if (result === true) {
|
||||
return
|
||||
}
|
||||
|
||||
return createError(result)
|
||||
return result
|
||||
})
|
||||
|
@ -90,6 +90,9 @@ describe('pages', () => {
|
||||
expect(html).toContain('[...slug].vue')
|
||||
expect(html).toContain('404 at not-found')
|
||||
|
||||
// Middleware still runs after validation: https://github.com/nuxt/framework/issues/9701
|
||||
expect(html).toContain('Middleware ran: true')
|
||||
|
||||
await expectNoClientErrors('/not-found')
|
||||
})
|
||||
|
||||
|
2
test/fixtures/basic/pages/[...slug].vue
vendored
2
test/fixtures/basic/pages/[...slug].vue
vendored
@ -2,11 +2,13 @@
|
||||
<div>
|
||||
<div>[...slug].vue</div>
|
||||
<div>404 at {{ $route.params.slug[0] }}</div>
|
||||
<div>Middleware ran: {{ !!($route.meta.override as any)?.includes('extended middleware') }}</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
definePageMeta({
|
||||
middleware: ['override'],
|
||||
validate: to => to.path !== '/forbidden'
|
||||
})
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user