Problem
After updating our Angular application to version 8 (including Angular CLI), URLs are not prefixed with the base href provided in the angular.json
file anymore, which essentially breaks our application
Previous, desired behaviour
When serving the French version of the app locally, opening a web page on localhost:8000
would redirect me to localhost:8000/fr
, and every URL I can navigate to from within the app would also be prefixed with /fr/
.
New, erroneous behaviour
When serving the French version of the app locally, opening a web page on localhost:8000
results in an empty page saying Cannot GET /
, since the /fr
is missing. When I open the page at localhost:8000/fr
right away, I can see the login page, but since our login flow involves a third party, when I come back to our app from said third party I only see a blank page saying Cannot GET /login
(because the /fr/
is missing).
What I have tried thus far (non-exhaustive list, but the two most promising approaches)
- Providing an
APP_BASE_HREF
DI token inside theAppModule
providers that would use theLOCALE_ID
as its value and removing thebaseHref
settings from theangular.json
configuration. This works "somewhat" in that I am redirected fromlocalhost:8000
to e.g.localhost:8000/fr/
, but it also results in undesired redirects because I assume the route lookup logic happens before the base href token is injected and thus it cannot recognize the URL and redirects to the default route. - Providing a
deployUrl
value inside theangular.json
configuration, to no avail.
Similar issues
https://github.com/angular/angular-cli/issues/14925 is basically the exact same issue. Unfortunately, all such issues have been closed without providing an actual solution on how to restore the old behaviour.