Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirect via navigateTo() not working with nuxt generate #14412

Closed
codeflorist opened this issue Jul 26, 2022 · 6 comments
Closed

redirect via navigateTo() not working with nuxt generate #14412

codeflorist opened this issue Jul 26, 2022 · 6 comments

Comments

@codeflorist
Copy link

Environment

  • Operating System: Linux
  • Node Version: v16.14.2
  • Nuxt Version: 3.0.0-rc.6
  • Package Manager: npm@7.17.0
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/nuxt-starter-zaokyb?file=pages/index.vue

Describe the bug

having a page redirect to another page via the navigateTo helper does not work with nuxt generate.

e.g.

<script setup lang="ts">
await navigateTo('/target', { replace: true })
</script>

gets rendered as a white page with the text Redirecting to /target.

see attached stackblitz-project for an example.

Additional context

No response

Logs

No response

@danielroe
Copy link
Member

What do you expect to happen? Should the page not be generated?

@codeflorist
Copy link
Author

What do you expect to happen? Should the page not be generated?

I would expect it to behave exactly like nuxt build or nuxt dev - meaning it should load the full page, then redirect to /target.

@danielroe
Copy link
Member

A server-side redirection can't be rendered as an HTML page as such. But what we could do is return a minimal blank white HTML page that immediate redirects to the target location on client-side, which seems reasonable and better than at present.

@codeflorist
Copy link
Author

A server-side redirection can't be rendered as an HTML page as such. But what we could do is return a minimal blank white HTML page that immediate redirects to the target location on client-side, which seems reasonable and better than at present.

ah, of course. i understand. many thanks for the clarification and the super fast reaction!

imho a workable solution would also be:

<script setup lang="ts">
onMounted(() => {
	navigateTo('/target', { replace: true })
})
</script>

@danielroe
Copy link
Member

Should already be implemented in h3 and you'll get the benefit in next h3 release 😊

@pi0 pi0 closed this as completed Aug 1, 2022
@pi0
Copy link
Member

pi0 commented Aug 1, 2022

Please use npx nuxi upgrade --force to update lockfile and have latest h3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants