From f4ba7ec82d2167160824c5c1364e039b21400b3b Mon Sep 17 00:00:00 2001 From: Julien Huang <63512348+huang-julien@users.noreply.github.com> Date: Sat, 14 Jan 2023 01:23:20 +0100 Subject: [PATCH] fix(nuxt): don't short circuit middleware after validate function (#9180) --- packages/nuxt/src/pages/runtime/validate.ts | 9 ++++----- test/basic.test.ts | 3 +++ test/fixtures/basic/pages/[...slug].vue | 2 ++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/nuxt/src/pages/runtime/validate.ts b/packages/nuxt/src/pages/runtime/validate.ts index 14d5a8aeddc..e66421d9a3e 100644 --- a/packages/nuxt/src/pages/runtime/validate.ts +++ b/packages/nuxt/src/pages/runtime/validate.ts @@ -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 }) diff --git a/test/basic.test.ts b/test/basic.test.ts index 81ba31c9967..8752d1fc437 100644 --- a/test/basic.test.ts +++ b/test/basic.test.ts @@ -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') }) diff --git a/test/fixtures/basic/pages/[...slug].vue b/test/fixtures/basic/pages/[...slug].vue index a805ed7aea9..8ed645e31ad 100644 --- a/test/fixtures/basic/pages/[...slug].vue +++ b/test/fixtures/basic/pages/[...slug].vue @@ -2,11 +2,13 @@