'ReactJS - Serving the Same Build from Different Paths

I try to run the same react app on different URLs but for now without success.

Description of the problem:

I have a react app that works perfectly fine when running both on localhost and on production url when served as a root (e.g www.myApp.com)

however what I'm trying to achieve is to have the same app run both on www.myApp.com and on www.anotherSite.com/myApp

What I've tried:

So I took a look at the Deployment section that can be found here:

https://create-react-app.dev/docs/deployment/

and I tried setting the homepage to "." but this ends in a situation where:

  1. www.myApp.com works as expected which is good

  2. www.anotherSite.com/myApp does not work at all -> white page with error showing enter image description here

I think it's the same problem that this guy has: https://github.com/facebook/create-react-app/issues/9183

  1. www.anotherSite.com/myApp/ (notice the / at the end) works but the paths are not working (I get redirected to my 404 Page).

I played arround with different combinations of the homepage, setting the basename for the Router and setting the <base href="%PUBLIC_URL%/"/> in index.html but nothing really works for both cases.

I was able to run the app on www.anotherSite.com/myApp by setting homepage: "/myApp/" but then www.myApp.com does not work.

Any idea what I'm doing wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source