Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(nuxt): add missing process.client for early redirect in navigateTo #7625

Merged
merged 3 commits into from Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/nuxt/src/app/composables/router.ts
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
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 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', () => {
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/basic/pages/navigate-to-redirect.vue
@@ -0,0 +1,11 @@
<template>
<div>You should not see me</div>
</template>

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