Skip to content
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: 4 comments 8 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
1 reply
@doaortu
Comment options

Comment options

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

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
9 participants