-
According to the documentation, a resource route must not define a default export, and then raw data can be returned from the loader. Say I want to have |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You could return an HTML response or a plain text response export async function loader({ request }: Route.LoaderArgs) {
let data = await getData(request)
let url = new URL(request.url)
if (url.searchParams.has("text")) return plain(formatToPlainText(data))
return html(formatToHTML(data))
} The function plain(data: string, init?: ResponseInit) {
let headers = new Headers(init?.headers)
headers.set("Content-Type", "text/plain")
return new Response(data, { ...init, headers })
}
function plain(data: string, init?: ResponseInit) {
let headers = new Headers(init?.headers)
headers.set("Content-Type", "text/html") // the only difference
return new Response(data, { ...init, headers })
} Then the Note that this HTML will not work as normal route in your app, like it won't load JS, but it will be plain HTML. If you want it to perform like a normal route, instead of a search param create a separate route, like |
Beta Was this translation helpful? Give feedback.
You could return an HTML response or a plain text response
The
plain
andhtml
functions can be wrappers ofnew Response
that sets the correct Content-Type header.