diff --git a/packages/nuxt/src/app/composables/router.ts b/packages/nuxt/src/app/composables/router.ts
index bb7f979b83..0ff1bdf21f 100644
--- a/packages/nuxt/src/app/composables/router.ts
+++ b/packages/nuxt/src/app/composables/router.ts
@@ -90,7 +90,7 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na
}
const toPath = typeof to === 'string' ? to : ((to as RouteLocationPathRaw).path || '/')
- const isExternal = hasProtocol(toPath, { acceptRelative: true })
+ const isExternal = options?.external || hasProtocol(toPath, { acceptRelative: true })
if (isExternal && !options?.external) {
throw new Error('Navigating to external URL is not allowed by default. Use `navigateTo (url, { external: true })`.')
}
diff --git a/test/basic.test.ts b/test/basic.test.ts
index 51178d6ef2..594a3d68a3 100644
--- a/test/basic.test.ts
+++ b/test/basic.test.ts
@@ -528,6 +528,12 @@ describe('navigate external', () => {
expect(headers.get('location')).toEqual('https://example.com/')
})
+
+ it('should redirect to api endpoint', async () => {
+ const { headers } = await fetch('/navigate-to-api', { redirect: 'manual' })
+
+ expect(headers.get('location')).toEqual('/api/test')
+ })
})
describe('middlewares', () => {
diff --git a/test/bundle.test.ts b/test/bundle.test.ts
index 1d2f5384f5..2520fcd29d 100644
--- a/test/bundle.test.ts
+++ b/test/bundle.test.ts
@@ -26,7 +26,7 @@ describe.skipIf(isWindows)('minimal nuxt application', () => {
it('default client bundle size', async () => {
stats.client = await analyzeSizes('**/*.js', publicDir)
- expect(stats.client.totalBytes).toBeLessThan(106500)
+ expect(stats.client.totalBytes).toBeLessThan(106600)
expect(stats.client.files.map(f => f.replace(/\..*\.js/, '.js'))).toMatchInlineSnapshot(`
[
"_nuxt/_plugin-vue_export-helper.js",
diff --git a/test/fixtures/basic/pages/navigate-to-api.vue b/test/fixtures/basic/pages/navigate-to-api.vue
new file mode 100644
index 0000000000..2fbb0c469d
--- /dev/null
+++ b/test/fixtures/basic/pages/navigate-to-api.vue
@@ -0,0 +1,7 @@
+
+ You should not see me
+
+
+