Multiple actions same route, action
placement with nested routes, and resource
route without export default
#1298
-
Hello friends, Thank you so much for giving back to the Web and React community by building and sharing Remix! I have built a trivial application to get a taste of how things work. Everything went super well. 👍 I have a few remarks/questions to confirm whether I'm doing something wrong or these are actually rough edges. Here's the repo to reproduce the below issues. How to have multiple
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Another solution is to import type { ActionFunction } from "remix";
enum FormType {
UpdateName = "UpdateName",
UpdateAvatar = "UpdateAvatar",
}
export const action: ActionFunction = async ({ request }) => {
const form = await request.formData();
switch (form.get("type") as FormType) {
case FormType.UpdateAvatar:
...
break;
case FormType.UpdateName:
...
break;
}
};
export default function Profile() {
return (
<>
<form method="post">
<input name="name" />
<input name="type" type="hidden" value={FormType.UpdateName} />
<button type="submit">Save</button>
</form>
<form method="post">
<input name="avatar" />
<input name="type" type="hidden" value={FormType.UpdateAvatar} />
<button type="submit">Save</button>
</form>
</>
);
} |
Beta Was this translation helpful? Give feedback.
-
I believe you are running into the behavior described here.
|
Beta Was this translation helpful? Give feedback.
-
As you noted, a resource route definitely does not have to You can prevent this behavior by renaming the source file to include a
|
Beta Was this translation helpful? Give feedback.
-
Thank you so much @jangerhofer for your detailed answers to all of my queries! Github should add a feature to allow selecting multiple answers. 😄 |
Beta Was this translation helpful? Give feedback.
As you noted, a resource route definitely does not have to
export default
anything. It is a bit of a shot in the dark, but without additional knowledge of the specific error(s) blocking page loads when you omitted the default export, I am going to guess that Remix (or reallyesbuild
under the hood) failed to split server code from client code. Specifically, my guess that code in~/lib/utils/session
which should only run on the server is bundled into your client build.You can prevent this behavior by renaming the source file to include a
.server.ts
suffix.