T
TanStack5mo ago
genetic-orange

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.
2 Replies
eastern-cyan
eastern-cyan5mo ago
From what I've read, In the next iteration of api route (with Vinxi removal), the /api folder limitation will go away, so sitemap.xml etc can be an api route directly
inland-turquoise
inland-turquoise5mo ago
yes exactly

Did you find this page helpful?