You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
redirect can be called in Client Components during the rendering process but not in event handlers.
Is there any context that might help us understand?
Since internally it's implemented as an exception, it's caught by error boundaries. I think that's worth calling out, because it almost completely negates the utility of ever using redirect() client-side.
Actually, after some digging I see that Next.js internally uses an error boundary that is redirect-aware, but not in a way that I can re-use in my repo. Have you considered exporting RedirectBoundary so that devs can use it directly?
That would allow me to make an in-house error boundary in which the redirect always comes first:
Ok, I've had a couple of days to play with it and I've come to the conclusion that even with the boundaries in place (as I've suggested above) this is still pretty error prone and should not be recommended as a pattern. I think the docs should discourage it.
What is the improvement or update you wish to see?
Right now the docs for the
redirect()
function say this:Is there any context that might help us understand?
Since internally it's implemented as an exception, it's caught by error boundaries. I think that's worth calling out, because it almost completely negates the utility of ever using
redirect()
client-side.I ran into this when I combined Sentry's ErrorBoundary with Next.js's
redirect()
.Does the docs page already exist? Please link to it.
https://nextjs.org/docs/app/building-your-application/routing/redirecting#redirect-function
The text was updated successfully, but these errors were encountered: