从angular 7升级到8后未加载自定义字体
我们刚刚将angular应用程序从7升级到8。我们已经加载了一些自定义字体,如下所示:从angular 7升级到8后未加载自定义字体,angular,fonts,Angular,Fonts,我们刚刚将angular应用程序从7升级到8。我们已经加载了一些自定义字体,如下所示: @font-face { font-family: "Source Sans Pro Light"; src: url("/assets/fonts/Source_Sans_Pro/SourceSansPro-Light.ttf"); } @font-face { font-family: "Source Sans Pro Semibold"; src: url
@font-face {
font-family: "Source Sans Pro Light";
src: url("/assets/fonts/Source_Sans_Pro/SourceSansPro-Light.ttf"); }
@font-face {
font-family: "Source Sans Pro Semibold";
src: url("/assets/fonts/Source_Sans_Pro/SourceSansPro-SemiBold.ttf");
升级到Angular 8后,字体不再加载。他们的错误是:
GET http://windows2/assets/fonts/Titillium_Web/TitilliumWeb-SemiBold.ttf net::ERR_ABORTED 404 (Not Found)
GET http://windows2/assets/fonts/Source_Sans_Pro/SourceSansPro-Light.ttf net::ERR_ABORTED 404 (Not Found)
GET http://windows2/assets/fonts/Source_Sans_Pro/SourceSansPro-Regular.ttf net::ERR_ABORTED 404 (Not Found)
请注意,只有在应用服务器上构建和部署时才会发生这种情况。当我们使用ng服务时,字体加载和显示都很好。我也有同样的问题。用下面的方法解决了这个问题
@font-face {
font-family: "Source Sans Pro Light";
src: url("./assets/fonts/Source_Sans_Pro/SourceSansPro-Light.ttf"); }
@font-face {
font-family: "Source Sans Pro Semibold";
src: url("./assets/fonts/Source_Sans_Pro/SourceSansPro-SemiBold.ttf");
请注意./assets而不是/assets
希望这有帮助