diff --git a/packages/nuxt/src/app/composables/router.ts b/packages/nuxt/src/app/composables/router.ts index 6cfe749c9ec..a16dbf7f04b 100644 --- a/packages/nuxt/src/app/composables/router.ts +++ b/packages/nuxt/src/app/composables/router.ts @@ -79,7 +79,7 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na } // Early redirect on client-side - if (!isExternal && isProcessingMiddleware()) { + if (process.client && !isExternal && isProcessingMiddleware()) { return to } diff --git a/test/basic.test.ts b/test/basic.test.ts index 3d86a69d9e2..554d2bb8a1d 100644 --- a/test/basic.test.ts +++ b/test/basic.test.ts @@ -265,6 +265,12 @@ describe('middlewares', () => { expect(html).toContain('auth: ') expect(html).not.toContain('Injected by injectAuth middleware') }) + + it('should redirect to index with http 307 with navigateTo on server side', async () => { + const html = await fetch('/navigate-to-redirect', { redirect: 'manual' }) + expect(html.headers.get('location')).toEqual('/') + expect(html.status).toEqual(307) + }) }) describe('plugins', () => { diff --git a/test/fixtures/basic/pages/navigate-to-redirect.vue b/test/fixtures/basic/pages/navigate-to-redirect.vue new file mode 100644 index 00000000000..b0c7bea0505 --- /dev/null +++ b/test/fixtures/basic/pages/navigate-to-redirect.vue @@ -0,0 +1,11 @@ + + +