Skip to content

POST Request to action returns page HTML instead of the response returned by the action #8547

Answered by kiliman
HadiMalikDev asked this question in Q&A
Discussion options

You must be logged in to vote

Calling fetch on a route will always return the HTML for that route. Remix doesn't know if it's a regular browser request or coming from fetch (it doesn't look at the accept header).

Based on your example, it doesn't appear you're using Remix as intended. For your login form, you could let the <Form> submit to your action directly and use useActionData to access the result.

If you must do an imperative fetch, then I suggest you use fetchers: https://remix.run/docs/en/main/hooks/use-fetcher

And finally, you can use fetch directly (that's what Remix does internally). You can call your route loader, but you need to specify the route id as a special _data search param (that's what Remix uses …

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
6 replies
@HadiMalikDev
Comment options

@jwayne
Comment options

@wave-light
Comment options

@spacepolice10
Comment options

@HadiMalikDev
Comment options

Answer selected by HadiMalikDev
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@moonstar-x
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
7 participants