diff --git a/packages/nuxt/src/app/composables/router.ts b/packages/nuxt/src/app/composables/router.ts index 750a1aeaf6..d6395e5832 100644 --- a/packages/nuxt/src/app/composables/router.ts +++ b/packages/nuxt/src/app/composables/router.ts @@ -169,8 +169,7 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na nuxtApp.ssrContext!._renderResponse = { statusCode: sanitizeStatusCode(options?.redirectCode || 302, 302), body: ``, - // do not encode as this would break some modules and some environments - headers: { location }, + headers: { location: encodeURI(location) }, } return response } diff --git a/test/basic.test.ts b/test/basic.test.ts index 7d0b11552a..9e4e0b6021 100644 --- a/test/basic.test.ts +++ b/test/basic.test.ts @@ -972,6 +972,12 @@ describe('navigate', () => { expect(status).toEqual(404) }) + + it('expect to redirect with encoding', async () => { + const { status } = await fetch('/redirect-with-encode', { redirect: 'manual' }) + + expect(status).toEqual(302) + }) }) describe('preserves current instance', () => { diff --git a/test/fixtures/basic/pages/redirect-with-encode.vue b/test/fixtures/basic/pages/redirect-with-encode.vue new file mode 100644 index 0000000000..a59a44d653 --- /dev/null +++ b/test/fixtures/basic/pages/redirect-with-encode.vue @@ -0,0 +1,9 @@ + + +