How to safely redirect to /login without crashing on heavy page renders?
Hi everyone,
I’m running into an issue with Nuxt 4 / Vue 3 where I need to redirect the user to /login immediately after logging them out or when a token expires. The problem is that if I call navigateTo('/login') while the current page is still rendering (for example, a heavy dashboard page), the app either blocks or crashes.
I’ve found that adding a setTimeout(() => navigateTo('/login'), 500) works, but it feels hacky and unreliable. I’ve also tried nextTick() and router.replace(), but on heavy pages it still fails.
Is there a clean and reliable way to force a redirect in Nuxt 4 that interrupts the current render or navigation safely, without reloading the whole PWA?
Code: (in a util function, called when pinia stores make requests)
Thanks in advance for any tips!
I’m running into an issue with Nuxt 4 / Vue 3 where I need to redirect the user to /login immediately after logging them out or when a token expires. The problem is that if I call navigateTo('/login') while the current page is still rendering (for example, a heavy dashboard page), the app either blocks or crashes.
I’ve found that adding a setTimeout(() => navigateTo('/login'), 500) works, but it feels hacky and unreliable. I’ve also tried nextTick() and router.replace(), but on heavy pages it still fails.
Is there a clean and reliable way to force a redirect in Nuxt 4 that interrupts the current render or navigation safely, without reloading the whole PWA?
Code: (in a util function, called when pinia stores make requests)
Thanks in advance for any tips!

