通常情况下,当部署 Angular 应用程序时 CSS 不显示可能是由于以下三个问题引起的:
styles.css
的文件,可以使用以下代码将其包含在 index.html
文件中:
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname + '/path/to/index.html'), {
headers: {
'Content-Type': 'text/html',
'Content-Type': 'text/css'
}
});
});
--extract-css true
标志来强制 Angular CLI 打包 CSS 文件。例如:ng build --prod --extract-css true
通过解决以上问题中的一个或多个,应该可以在部署 Angular 应用程序后正确加载样式表。