NuxtN
Nuxt3y ago
Gendarme

Redirect on initial load; conflicts with hydration

Greetings. I am wondering about the implementation of a rather simple "pattern" that is common but somehow I alone seem to be struggling with.

I wish to redirect logged in users from the index page to /home (which is common on the web). What I am trying to do is to—in the middleware—poll the backend to see if I am logged in and navigateTo("/home") if true. The problem is that this breaks with SSR, since I would be redirecting during hydration.

Is my approach stupid? Is the redirect perhaps supposed to be initiated from the backend... somehow? Is it possible to somehow "await" hydration and redirect afterwards?

After extensive searches I have only found one Github issue with the same problem but without a solution: https://github.com/nuxt/nuxt/issues/15136
GitHub
Environment Operating System: Linux Node Version: v16.14.2 Nuxt Version: 3.0.0-rc.11 Nitro Version: 0.5.4 Package Manager: npm@7.17.0 Builder: vite User Config: - Runtime Modules: - Build Modules: ...
Was this page helpful?