-
I am in the process of migrating my project to use Single Fetch, I am mostly done apart from redirects. I'd just like some clarification on the documentation at https://remix.run/docs/en/main/guides/single-fetch where it states:
So I take this to read that I should move away from using redirect() in loaders/actions when using single fetch. I currently use throw redirect('go-here') in a lot of places, so idiomatically am I supposed to replace all of these by specifically setting a response status and Location header instead? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Don't worry about setting the response stub status and headers for these as you can add those directly. The only time you need to use the response stub is if you're returning a naked object. throw redirect('/', { status: 301, headers: { ... } }) You still need to return a |
Beta Was this translation helpful? Give feedback.
-
@janhesters Looks like there are two redirect functions:
For me, I have some paths that are the same origin but not handled by remix that I want to be able to redirect to. Switching |
Beta Was this translation helpful? Give feedback.
throw redirect
or throwing anyResponse
is still an acceptable pattern. You just don't want to return responses directly because Single Fetch doesn't know how to interpret the response body.Don't worry about setting the response stub status and headers for these as you can add those directly. The only time you need to use the response stub is if you're returning a naked object.
You still need to return a
Response
directly in Resource Routes since Remix doesn't process the response. It simply sends it as-is to the client.