Remix.run create resource route along with a UI route

lawrencecchen

Lawrence Chen

Posted on January 12, 2022

Remix.run create resource route along with a UI route

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";
Enter fullscreen mode Exit fullscreen mode

Note that we escape [.json] due to Remix conventions

💖 💪 🙅 🚩
lawrencecchen
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