question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot redirect to different app on same domain from loader function

See original GitHub issue

What version of Remix are you using?

1.5.1

Steps to Reproduce

I have a Remix Form that submits a GET request to a UI-route’s loader function, which can either return a JSON object or redirect the user to different places depending on the value of a query parameter.

For instance, these are the 2 only properties that I set on my Remix Form:


<Form method="get" action="/product-A">...</Form>

Let’s say the domain of my application is mywebsite.com, and when the form is submitted the query looks like this: mywebsite.com/product-A?area=11103.

The loader function has 3 possible outcomes:

  1. return json(payload) and renders the UI-route. This works ✅
  2. redirect user to an external website through redirect('differenwebsite.com'). This works ✅
  3. redirect user to mywebsite.com/product-B, which is a route on the same domain that is handled by a separate NextJS application. This doesn’t work, Remix shows a 404 page under mywebsite.com/product-B

In order to make the Form work in every scenario, I’d have to use the reloadDocument property, but that would be detrimental for the “happy path” UX.

Expected Behavior

I’d expect loader functions to be able to redirect to routes that live on the same domain, even though those routes are not part of the Remix application.

I’d expect to do so without resorting to the use of the reloadDocument directive on the Form.

Actual Behavior

Remix shows a 404 error page when a Form submission to a loader function results into a redirection to a route that is handled by a different application on the same domain.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:11

github_iconTop GitHub Comments

5reactions
kilimancommented, Jul 16, 2022

This code is what’s causing the issue. It checks the redirect URL’s origin and compares it to the current location. If the same, then it simply does a client side transition.

Perhaps, they could support adding a header X-Remix-Force-Redirect: true, that will do window.location.replace() like for external URLs.

let forceRedirect = response.headers.get('X-Remix-Force-Redirect') === 'true'
if (forceRedirect || url.origin !== window.location.origin) {
 ...
}

https://github.com/remix-run/remix/blob/99d98bd85897fcb37f4bd1e22f778d7c4d89198d/packages/remix-react/routes.tsx#L212-L234

3reactions
anton-paskannycommented, Oct 11, 2022

Any progress on this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redirect one domain to another domain using an Application ...
To confirm that the redirect is working: 1. In the AWS CLI, use the curl function. curl -Iv https://example1.com -L * Rebuilt URL ......
Read more >
react-router redirect to a different domain url - Stack Overflow
The question is "how do I redirect my app on a button click to an external url?". The question generalises to "how to...
Read more >
How to redirect to another URL using a JavaScript redirect?
With a few lines of JavaScript code, you can redirect visitors to another URL. The recommended function is window.location.replace() .
Read more >
Web Security - Cypress Documentation
Your application's code executes the same as it does outside of Cypress, ... that causes your web server to redirect to you a...
Read more >
Configuring Routes and Domains | Cloud Foundry Docs
Developers in one space cannot create a route with the same URL as ... Cloud Foundry apps can communicate with each other securely...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found