angular-cli "ng build" doesn't produce a working project?

I'm new to angular, and just ran into the same issue. You can open up and run the Index.html file in the browser directly from the file system, but you have to edit the path of the base href attribute in Index.html from:

<base href="/">

to:

<base href="./">

I thought I would cross post my answer from a similar question. Original Post.
I don't think the OP is a duplicate, so here;


You can achieve the desired outcome with the following cmd angular-cli command:

ng build --base-href /myUrl/

ng build --bh /myUrl/ or ng build --prod --bh /myUrl/

This changes the <base href="/"> to <base href="/myUrl/"> in the built version only which was perfect for our change in environment between development and production. The best part was no code base requires changing using this method.


To summarise, leave your index.html base href as: <base href="/"> then run ng build --bh ./ in angular-cli to make it a relative path, or replace the ./ with whatever you require.

This is the official angular-cli documentation referring to usage.