Redirect()
function not working on Client Component
#59162
Answered
by
icyJoseph
pedro757
asked this question in
App Router
-
I'm on v14.0.3 |
Beta Was this translation helpful? Give feedback.
Answered by
icyJoseph
Dec 1, 2023
Replies: 1 comment 10 replies
-
Code snippet?
|
Beta Was this translation helpful? Give feedback.
10 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah, so you have it within a click handler, and AFAIK, that's not gonna work.
The reason is the way the
redirect
function is designed.In short, it is equivalent of
throw new Error(/* something */)
, and as you know, when you throw an error as you render, you activate the closest Error Boundary:next.js/packages/next/src/client/components/redirect-boundary.tsx
Line 12 in cc42e43
In this case, that boundary checks if the error encountered, is a redirect error type, if not, then the boundary itself throws again, to propagate the error up the React tree. If it is a Redirect error, then it does the redirection. That's how it works in Clien…