#Is there a header or some way to get json directly from a UI route without getting html?

1 messages · Page 1 of 1 (latest)

smoky niche
#

For example, what if I want to have an html page at /users/:id but also be able to fetch just the loader JSON.

Only way I can see to do it is to add a resource route that imports the loader and action:

export { loader, action } from 'users.$id._index.tsx'```

Not terrible, but would be nice to avoid a bunch of these one-line files inside `routes/`
hoary bolt
#

That's the recommended way

#

There's an undocumented param ?_data=users.$id.json you can add, which remix uses internally for data requests (check the network tab when you client side navigate)

#

But that is liable (even likely) to break on any new version of Remix

#

it's not a public api

smoky niche
#

Interesting. Wait, maybe that means that I can use const fetcher = useFetcher() and fetcher.load('users/123). Let me try that

sacred gull
#

That's the official "remix" way to client-side grab loader json from any route.

#

You won't have to worry about it breaking at some point.