Correct Usage of redirect() with App Router in Next.js
When using (App Router) in Next.js, calling the redirect() function actually throws an exception. This is a method Next.js uses to trigger its own routing mechanism. In other words, when you call redirect("/dashboard"), a special NEXT_REDIRECT error is thrown in the background, and the remaining code execution is stopped. This exception is caught by Next.js and the user is redirected to the specified page. There is no real error here; the redirection is successfully completed. However, if you wrap the redirect() function inside a try/catch block, the exception will be caught by your catch block. As a result, Next.js will not be able to complete the redirection. Moreover, since the exception is usually re-thrown, it may appear as an actual error and display an error page. Therefore, the redirect() function should be called directly, outside of any try/catch block. If you need to perform error handling before redirecting, you should throw an error only when necessary, and call redirect() directly on successful conditions.

When using (App Router) in Next.js, calling the redirect() function actually throws an exception. This is a method Next.js uses to trigger its own routing mechanism.
In other words, when you call redirect("/dashboard"), a special NEXT_REDIRECT error is thrown in the background, and the remaining code execution is stopped. This exception is caught by Next.js and the user is redirected to the specified page. There is no real error here; the redirection is successfully completed.
However, if you wrap the redirect() function inside a try/catch block, the exception will be caught by your catch block. As a result, Next.js will not be able to complete the redirection. Moreover, since the exception is usually re-thrown, it may appear as an actual error and display an error page. Therefore, the redirect() function should be called directly, outside of any try/catch block.
If you need to perform error handling before redirecting, you should throw an error only when necessary, and call redirect() directly on successful conditions.