Use multiple actions on same route #1052
-
Hi, I'm trying to use multiple actions on same route. I've put action in other file, but for some reason I get an error Folder structure:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
An action needs to return one of two things.
The redirect works all the time, the data to be accessed through useActionData will only work if the action is on a route with a component. So in your case because you moved the action to another file you need to do a redirect, in case of an error you should store any error message in the session with If you want to keep using useActionData you need to move the action function back to the same route of the form. The reason why useActionData doesn't work with an action in a different route is because a form submit is causing a navigation, so you are going from |
Beta Was this translation helpful? Give feedback.
An action needs to return one of two things.
The redirect works all the time, the data to be accessed through useActionData will only work if the action is on a route with a component.
So in your case because you moved the action to another file you need to do a redirect, in case of an error you should store any error message in the session with
session.flash
, redirect to the previous URL (you can use redirectBack from Remix Utils) and then in the loader read the errors from the session withsession.get
and return them as part of the loader data.If you want to keep using useActionData you need…