I currently have a React Router v7 application running in SPA mode. I wanted to make an API route that uses a clientAction to submit data to an endpoint. If I use the useSubmit hook, I can successfully POST to that client action. But if I use the native fetch api then I get an error from react-i18next reading TypeError: i18n.dir is not a function. In my logs I see Error: You made a POST request to "/api-sammi" but did not provide an action for route "routes/api-sammi", If I include logging, I can confirm that the clientAction is never reached.
I think this might be a limitation to SPA mode but I can't find anything in the docs that support that theory. If anyone can point me in the right direction please let me know!
**_app/projects/test/route.tsx**
export default function Component() {
return (
<>
<Button
onPress={() => {
void fetch(`/api-test`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
message: "Hello, world!",
}),
});
}}
>
{"Validate Data"}
</Button>
</>
);
}
**api-test/route.ts**
export async function clientAction({ request }: ClientActionFunctionArgs) {
console.log("Received request:", request);
const body = await request.json();
console.log("Received request body:", body);
return Response.json({
message: "Hello, world!",
received: body,
success: true,
});
}