Remix.run create resource route along with a UI route
Lawrence Chen
Posted on January 12, 2022
Some websites like Reddit expose a .json
endpoint alongside each post. For example, the posts shown in https://www.reddit.com/r/rickroll/
are also exposed in https://www.reddit.com/r/rickroll.json
.
Here's how we can do the same in Remix:
If $postId.tsx
was our post's UI route, we can create a file called $postId[.json].ts
with the following:
export { loader } from "./$postId";
Note that we escape [.json]
due to Remix conventions
💖 💪 🙅 🚩
Lawrence Chen
Posted on January 12, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
watercooler Why does a reboot make your PC run SO much faster than running all the cleaning tools you can possibly imagine?
November 30, 2024