Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular 2: assets not loaded when deployed in subdirectory

I'm trying to deploy my angular 2 app in a sub directory: I searched SO and google, and found I've to build it with the following command:

ng build -prod --base-href /angular-test --deploy-url /angular-test

but it's still not loading the assets.

Under networks in inspect, call to assets are going with:

/assets/i18n/en.json

whereas it should be

/angular-test/assets/i18n/en.json

Do I need to do something else? Any help is appreciated.

like image 744
Drunken Daddy Avatar asked Sep 08 '17 05:09

Drunken Daddy


2 Answers

replace ../../../assets/images/example.jpg to ./assets/images/example.jpg then it worked for me.

like image 175
Vamshi Rockzz Avatar answered Oct 05 '22 02:10

Vamshi Rockzz


Most of the examples I've seen are of this format:

ng build --base-href /myUrl/

So I would think you would need this:

ng build --prod --base-href /angular-test/

( With a trailing slash )

like image 27
DeborahK Avatar answered Oct 05 '22 03:10

DeborahK