DEV Community

Lawrence Chen
Lawrence Chen

Posted on

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

Top comments (0)