I understand your issue with server-side redirects in Nuxt. The behavior you're experiencing is expected based on how server components and navigation work in Nuxt.
When you use a .server.vue component, the code runs exclusively on the server. When you call navigateTo with an external URL from a server component, it attempts to perform a server-side redirect by setting HTTP headers. This is why you're seeing a 302 status code - it's actually a redirect status code, not an error.
The issue is that server-side redirects work differently than client-side redirects. On the server, redirects are handled by sending a Location header to the browser, which then makes a fresh request to the new location. As mentioned in the Nuxt documentation:
Any redirection on the server will result in a Location: header being sent to the browser; the browser then makes a fresh request to this new location. All application state will be reset when this happens, unless persisted in a cookie.
Nuxt Lifecycle
When you remove the .server suffix, the component runs on both server and client, but the navigation happens on the client side, which works as expected.
For external redirects in server components, you might want to consider using Nitro's sendRedirect function instead of navigateTo. However, this would need to be done in a server route rather than a page component.
Alternatively, if you want to stick with your current approach, you could:
- Keep using a regular page component (without
.server) and perform your API calls with useFetch
- Use
navigateTo for the redirect based on the results