From cef5da6e1a63742f058601cf8ef92c14db2900a7 Mon Sep 17 00:00:00 2001 From: wattanx Date: Wed, 18 Sep 2024 22:16:29 +0900 Subject: [PATCH] fix: avoid throwing a 404 error before the middleware is executed --- packages/nuxt/src/pages/runtime/plugins/router.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/packages/nuxt/src/pages/runtime/plugins/router.ts b/packages/nuxt/src/pages/runtime/plugins/router.ts index 7f2e5faca6..ca1d570244 100644 --- a/packages/nuxt/src/pages/runtime/plugins/router.ts +++ b/packages/nuxt/src/pages/runtime/plugins/router.ts @@ -148,16 +148,8 @@ const plugin: Plugin<{ router: Router }> = defineNuxtPlugin({ if (import.meta.server && failure?.type === 4 /* ErrorTypes.NAVIGATION_ABORTED */) { return } - if (to.matched.length === 0) { - await nuxtApp.runWithContext(() => showError(createError({ - statusCode: 404, - fatal: false, - statusMessage: `Page not found: ${to.fullPath}`, - data: { - path: to.fullPath, - }, - }))) - } else if (import.meta.server && to.redirectedFrom && to.fullPath !== initialURL) { + + if (import.meta.server && to.redirectedFrom && to.fullPath !== initialURL) { await nuxtApp.runWithContext(() => navigateTo(to.fullPath || '/')) } })