Loading...
redirect() inside a Server Action doesn’t work, the catch block runs instead
asked 4 hours ago
0
3
I have a Server Action that creates a post and should then redirect to the new page. The post is saved in the database, but the redirect never happens. The catch block runs instead and logs an error called NEXT_REDIRECT.
ts
The form shows “Could not create post”, even though the post exists. If I remove the try/catch, the redirect works fine.
Why is redirect() being caught as an error? And what’s the clean way to keep the error handling and still redirect afterwards?
I’m on Next.js 15 with the App Router.
0 Answers


No Answers Found
The answer board is empty. Make it rain with your brilliant answer.
1