What is Remix's resource routes feature?
Answer
Resource routes in Remix are routes that don't render React components — they return non-UI responses like JSON, XML, CSV, images, or redirects. They only have loaders and/or actions, no default export component. Examples: JSON API endpoint: export async function loader({ params }) { return json(await db.getPost(params.id)); }. Sitemap: export async function loader() { const posts = await db.getPosts(); return new Response(generateSitemap(posts), { headers: { "Content-Type": "application/xml" } }); }. File download: return a Response with the file content and appropriate headers. Redirect: return redirect("/new-path"). OAuth callback handler: process the code, set cookies, redirect. Resource routes enable building REST APIs alongside UI routes in the same Remix app without a separate backend. They use the same loader/action conventions, making code sharing between UI and API routes easy.