DEV Community

Lawrence Chen
Lawrence Chen

Posted on

4 2

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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay