Open pedro757 opened 9 months ago
redirect
is function that can only be used in server components, you should instead use router.push()
on the client.
redirect
is function that can only be used in server components, you should instead userouter.push()
on the client.
In the first paragrapth the docs say we can use it in client components, however I believe the explanation to this problem is this
If that's the case, I wonder what an use case for redirect in client components would be?
redirect
in server components/actions doesn't seem to work if it's being called in a trycatch
block.
redirect in server components is not working for me in try/catch block
To perform client-side navigation (redirect) in a client component, you should use the router.push()
method from Next.js's useRouter
hook. , replace the redirect()
call with router.push()
.
Link to the code that reproduces this issue
https://github.com/pedro757/redirect-issue-client-components
To Reproduce
Current vs. Expected behavior
Currently it's not redirecting to the otherpage I expect to actually redirect to the otherpage
Verify canary release
Provide environment information
Which area(s) are affected? (Select all that apply)
App Router, Routing (next/router, next/navigation, next/link)
Additional context
I have used redirect in server actions and it seems to be working good, the problem seems to be on client components