angular throws 404 for *.bundle.js files when using a custom html5 base url

Viewed 2343

Symptom

After upgrading my Angular2 app to Angular ^4.1.2 and also the Angular CLI beta to ^1.0.3, I got a 404 not found for my *.bundle.js files when running the app with ng serve. Note, that this symptom didn't occur in Angular2 and Angular CLI beta.

Setup

This issue only exists when I set the html5 base url to a custom url in index.html, e.g. <base href="/some-path/">. (I.e. if I set it to <base href="/">, the *.bundle.js files are found and my app works)

Investigation

The symptom occurs under the described circumstances, because the files are served on a root level by angular cli, no matter what the html5 base url is. So the real question is: How can I tell Angular CLI to serve the *.bundle.js files on the specified base url OR tell angular to pick up the files on root? I found an issue request that seems to deal with exactly this problem. Therefore, there is an option --base-href for the ng serve and ng build commands.

I tried using these options isolated as well as combined:

  • ng serve --base-href /assessment/
  • ng serve --base-href /assessment/ --deploy-url /assessment/

However, the symptom remained.

2 Answers
Related