TanStackT
TanStack10mo ago
2 replies
full-green

Loader responses for "non-components"

I've seen a few conversations around how to generate things like sitemap.xml and robots.txt, with the best approach so far being to create an API route (eg. /api/sitemap) with a Nitro redirect (/sitemap.xml => /api/sitemap). This works okay-ish.

This made me think, have you considered allowing
Response
objects to be returned from a file route's
loader
? If it is a
Response
object, the whole component tree can be ignored in favour of the
Response
.

This approach would allow creating dynamic sitemaps and similar files quite trivially.
Was this page helpful?