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

Symptom

After upgrading my Angular2 app to Angular ^4.1.2

and also the Angular beta for ^1.0.3

, I got a 404 not found for my * .bundle.js files when I run the app with ng serve

. Please note that this symptom was not seen in the Angular2 beta and Angular CLI.

Setting up

This problem only exists when I set the base url html5 to a custom url in index.html

eg. <base href="/some-path/">

... (Ie, if I install it on <base href="/">

, the files *.bundle.js

are located and my application works)

Study

The symptom happens in the circumstances described because the files are served at the root level using Angular cli, no matter what the base url is html5. So the real question is: How can I tell Angular CLI to serve * .bundle.js files at a specified base url OR tell Angular to pick up root files? I found a release question that seems to address exactly this issue. Therefore ng serve

, ng build

there is an option for teams --base-href

.

I have tried using these options both isolated and combined:

  • ng serve --base-href /assessment/

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

However, the symptom remained.

+3


source to share


2 answers


This worked for me:



  • don't add a custom route to index.html

    and develop locally/

  • use ng build --base-href /assessment/

    to build angular app. This will create a route in the dist file and hence work in prod.
0


source


I have the same problem and have been looking at StackOverflow and Github for a while. I find a solution that works for me.



Try this, $ng serve --base-href '/assessment/' --deploy-url '/'

it is working on my project.

0


source







All Articles