mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): add missing process.client
for early redirect in navigateTo (#7625)
This commit is contained in:
parent
fc41df04a5
commit
c4fe8525ef
@ -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
|
||||
}
|
||||
|
||||
|
@ -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', () => {
|
||||
|
11
test/fixtures/basic/pages/navigate-to-redirect.vue
vendored
Normal file
11
test/fixtures/basic/pages/navigate-to-redirect.vue
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<div>You should not see me</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
definePageMeta({
|
||||
middleware: () => {
|
||||
return navigateTo({ path: '/' }, { redirectCode: 307 })
|
||||
}
|
||||
})
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user