diff --git a/packages/nuxt/src/app/composables/router.ts b/packages/nuxt/src/app/composables/router.ts index cab9987dd0..383433cce9 100644 --- a/packages/nuxt/src/app/composables/router.ts +++ b/packages/nuxt/src/app/composables/router.ts @@ -118,7 +118,7 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na const fullPath = typeof to === 'string' || isExternal ? toPath : router.resolve(to).fullPath || '/' const location = isExternal ? toPath : joinURL(useRuntimeConfig().app.baseURL, fullPath) - async function redirect () { + async function redirect (response: any) { // TODO: consider deprecating in favour of `app:rendered` and removing await nuxtApp.callHook('app:redirected') const encodedLoc = location.replace(/"/g, '%22') @@ -127,16 +127,16 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na body: `
`, headers: { location } } - return inMiddleware ? /* abort route navigation */ false : undefined + return response } // We wait to perform the redirect last in case any other middleware will intercept the redirect // and redirect somewhere else instead. if (!isExternal && inMiddleware) { - router.afterEach(final => (final.fullPath === fullPath) ? redirect() : undefined) + router.afterEach(final => final.fullPath === fullPath ? redirect(false) : undefined) return to } - return redirect() + return redirect(!inMiddleware ? undefined : /* abort route navigation */ false) } } diff --git a/packages/nuxt/src/app/entry.ts b/packages/nuxt/src/app/entry.ts index db77ed4823..4aca681905 100644 --- a/packages/nuxt/src/app/entry.ts +++ b/packages/nuxt/src/app/entry.ts @@ -41,6 +41,7 @@ if (process.server) { await nuxt.hooks.callHook('app:error', err) nuxt.payload.error = (nuxt.payload.error || err) as any } + if (ssrContext?._renderResponse) { throw new Error('skipping render') } return vueApp } diff --git a/packages/nuxt/src/core/runtime/nitro/renderer.ts b/packages/nuxt/src/core/runtime/nitro/renderer.ts index 14c914ecbb..02ed61eae6 100644 --- a/packages/nuxt/src/core/runtime/nitro/renderer.ts +++ b/packages/nuxt/src/core/runtime/nitro/renderer.ts @@ -247,6 +247,9 @@ export default defineRenderHandler(async (event): Promise