Angular 4 & Universal SSR - Style not loaded right

2019-06-10 04:56发布

问题:

I have webpage that using Angular 4. When accessing using domain base i.e. www.mydomain.com site loads right.

When accessing using url folder i.e. www.mydomain.com/folder/page the styles are not loaded from right place: www.mydomain.com/folder/styles.[hash].bundle.css I'm getting 200 http but not the right css response. Thus my site looks without css.

Inside my index.html I have this line:

<head>
  <base href="/">

That still doesn't work.

回答1:

I found this solution here: The wrong styles bundle path

That worked for me. Since I used Universal SSR I had to change this line:

ng build --prod --deploy-url / && ng build --prod --app 1 --output-hashing=false

By adding --deploy-url /