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

This commit is contained in:
Julien Huang 2022-09-19 10:54:35 +02:00 committed by GitHub
parent fc41df04a5
commit c4fe8525ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View File

@ -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
}

View File

@ -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', () => {

View File

@ -0,0 +1,11 @@
<template>
<div>You should not see me</div>
</template>
<script setup>
definePageMeta({
middleware: () => {
return navigateTo({ path: '/' }, { redirectCode: 307 })
}
})
</script>