-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redirects caused outside of Remix are not handled correctly #4183
Comments
The issue is that if Remix does a client side fetch to your loader (which happens when you click on the I have an example here: https://github.com/kiliman/express-auth-example/blob/4aed9f0bfeb85d7cc73d4e8232cbaf9cd1a1d1c3/server/index.js#L78 const url = new URL(`${req.protocol}://${req.get('host')}${req.originalUrl}`)
const isDataRequest = url.searchParams.has('_data')
if (isDataRequest) url.searchParams.delete('_data')
const returnUrl = encodeURI(`${url.pathname}${url.search}`)
const redirectUrl = `/login?returnUrl=${returnUrl}`
return isDataRequest
? // special handling for redirect from data requests
res.status(204).set('x-remix-redirect', redirectUrl).send()
: res.redirect(redirectUrl) |
In my case we use a reverse proxy that handles all redirects (so its outside of Remix's environment completely), so having to make the reverse proxy handle redirects differently just for Remix is in my opinion not really great. Remix's |
The problem with the approach in that PR is that it makes an assumption that the redirect coming from the By default export default function FooRedirect() {
const data = useLoaderData();
return <div>foo-redirect: {data}</div>;
} There is actually a Proposal that I think would cover this which is considering the use of a custom header to indicate that the redirect should be followed via |
What version of Remix are you using?
1.7.0
Steps to Reproduce
server.js
to redirect/foo-redirect
to/foo
foo.tsx
andfoo-redirect.tsx
and add a loader to bothindex.tsx
and create a<Link to="/foo-redirect">..</Link>
component<Link>
componentExample repo: https://github.com/dylanblokhuis/remix-redirect-bug.git
Expected Behavior
That the redirect is being followed and the user ends up on
/foo
Actual Behavior
Redirect is not being followed and the user ends up on
/foo-redirect
The text was updated successfully, but these errors were encountered: