So it looks like the reason everyone usually absolute paths is that webpack doesn't support relative urls in its publicPath config for SPAs as it's convention to use a single HTML document for the entire SPA. That way the backend doesn't need to be aware of routing.
Let's say you have a route at /meow/foo that serves some page. Then a relative path like ./bundle.js for that route refers to /meow/bundle.js and not ./bundle.js. But of course you want the latter served. So webpack would need to adjust the relativity of each path in the HTML for each request which isn't something it currently supports.
The other option is to statically render each route but that's beyond CRA.
And you can modify the app's expected absolute public path with $PUBLIC_URL at runtime which isn't too bad so I'll just document that.
Activity
nhooyr commented on Feb 4, 2021
See also react/create-react-app#8623
Allow relative $PUBLIC_URL in dev mode
Allow relative $PUBLIC_URL in dev mode
Allow relative $PUBLIC_URL in dev mode
Allow relative $PUBLIC_URL in dev mode
nhooyr commented on Feb 4, 2021
Opened react/create-react-app#10503
Allow relative $PUBLIC_URL in dev mode
nhooyr commented on Feb 5, 2021
So it looks like the reason everyone usually absolute paths is that webpack doesn't support relative urls in its publicPath config for SPAs as it's convention to use a single HTML document for the entire SPA. That way the backend doesn't need to be aware of routing.
Let's say you have a route at /meow/foo that serves some page. Then a relative path like ./bundle.js for that route refers to /meow/bundle.js and not ./bundle.js. But of course you want the latter served. So webpack would need to adjust the relativity of each path in the HTML for each request which isn't something it currently supports.
The other option is to statically render each route but that's beyond CRA.
And you can modify the app's expected absolute public path with $PUBLIC_URL at runtime which isn't too bad so I'll just document that.
Update proxy path passthrough documentation
Update proxy path passthrough documentation
Update proxy path passthrough documentation
jsjoeio commented on Feb 5, 2021
See #2674