redirect not work outside loader #8311
-
if I write this:
this works ! But if I write this:
then it won't redirect ... Why will this happen? |
Beta Was this translation helpful? Give feedback.
Answered by
kiliman
Dec 17, 2023
Replies: 1 comment 6 replies
-
Return the above statement. export const loader = async () => {
if (condition) {
return myFunc(); // <<<<<<<<<<<
}
} |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As @jamalsoueidan said, you needed to return the result from the function.
Another option is to
throw redirect()
. This way you don't have to do the return.A typical pattern is to validate the user is logged in and redirect to the login page if not.