Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/nuxt/src/app/composables/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/basic/pages/navigate-to-redirect.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<div>You should not see me</div>
</template>

<script setup>
definePageMeta({
middleware: () => {
return navigateTo({ path: '/' }, { redirectCode: 307 })
}
})
</script>