首页 > 解决方案 > Angular 8 CSS 不会在刷新、生产构建时加载

问题描述

我的 index.html 看起来像这样:

<!doctype html>
<html lang="hu">
<head>
  <meta charset="utf-8">
  <title>WebsiteName</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
<!-- etc -->

当我使用“ng build”时,代码运行良好,但是当我在生产模式下编译它(使用“ng build --prod”)时,它似乎运行良好,但重新加载时会禁用 style.css。

更新:@Elizaveta 的回答是正确的,但是新的问题是

  <link rel="stylesheet" href="styles.d42b9ef58619804546db.css">

由“ng build --prod”生成,如下所示:

<link rel="stylesheet" href="styles.d42b9ef58619804546db.css"><!doctype html>
<html lang="hu">
<head>
  <meta charset="utf-8">
  <title>Nebulónia</title>
  <base href="/">

<!-- etc -->

我如何告诉 Angular 在哪里生成它?

这是完整的 github 仓库:https ://github.com/lori2001/NebuloniaWebsite

标签: angulartypescriptroutespage-refresh

解决方案


问题是您指向 css 的链接出现在基本 href 标记之前。

实际标签放置

它应该是:

<base href="/">
<link rel="stylesheet" href="styles.d42b9ef58619804546db.css">

用于通过浏览器进行正确的 css 处理。


推荐阅读