From 0a06dbef28d5107d6f5bcef16c98595cc5a97f8f Mon Sep 17 00:00:00 2001 From: julien huang Date: Sat, 17 Sep 2022 13:50:53 +0200 Subject: [PATCH 1/3] test(nuxt): new navigateTo in middlewazre redirect --- test/basic.test.ts | 6 ++++++ test/fixtures/basic/pages/navigate-to-redirect.vue | 11 +++++++++++ 2 files changed, 17 insertions(+) create mode 100644 test/fixtures/basic/pages/navigate-to-redirect.vue diff --git a/test/basic.test.ts b/test/basic.test.ts index 3d86a69d9e2..6282fc5bd3e 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 navigateToOption', 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 @@ + + + From f194c81447e21b4eb240a98932ab2bdd1a00d641 Mon Sep 17 00:00:00 2001 From: julien huang Date: Sat, 17 Sep 2022 18:15:12 +0200 Subject: [PATCH 2/3] fix(nuxt): add missing process.client --- packages/nuxt/src/app/composables/router.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 } From d9a89d8a6e8bc9e78df33e6dfc4f1ad5df43cf24 Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Mon, 19 Sep 2022 10:40:41 +0200 Subject: [PATCH 3/3] Update test/basic.test.ts --- test/basic.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/basic.test.ts b/test/basic.test.ts index 6282fc5bd3e..554d2bb8a1d 100644 --- a/test/basic.test.ts +++ b/test/basic.test.ts @@ -266,7 +266,7 @@ describe('middlewares', () => { expect(html).not.toContain('Injected by injectAuth middleware') }) - it('should redirect to index with http 307 with navigateToOption', async () => { + 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)