【问题标题】:Why does ng serve result in 404 error for JS files?为什么 ng serve 会导致 JS 文件出现 404 错误?
【发布时间】:2019-09-02 09:01:23
【问题描述】:

背景:我有一个使用多种语言的 Angular 网站

默认:/desktop/

英语:/en/

西班牙语:/es/

问题:我无法为 /en/ 或 /es/ 加载某些 javascript 文件,但在 /desktop/ 上运行时它们加载正常(我使用以下 SO 文章获取至此:Failed to Load。我还查看了:this thread。这似乎不同,因为它不仅仅是一个站点配置指向错误的文件夹,我有多个站点(语言)

详细信息:我的“桌面”批处理文件包含以下内容:

cd program-Desktop
call ng serve --base-href "/desktop/" --deploy-url "/desktop" --configuration=local-en

对于“en”站点批处理文件,我试过了:

call ng serve --base-href "/en/" --deploy-url "/desktop" --configuration=local-en

call ng serve --base-href "/en/" --deploy-url "/en" --configuration=local-en

实际结果:但是我仍然收到如下错误:

获取http://localhost:4200/desktop/assets/js/Scripts/jquery-2.1.1.js

net::ERR_ABORTED 404(未找到)

注意这在 REL 和 PROD 中运行良好。但是在本地遇到麻烦

问题:我不知道为什么当我告诉它 /en 时它仍在 /desktop 中查找。 如果我去 /en/ 的地址我可以看到那里的 js 文件,那为什么还在 /desktop 中寻找它呢?

【问题讨论】:

    标签: angular angular-cli http-status-code-404 href


    【解决方案1】:

    在 index.html 文件中,它告诉 Angular 程序在哪里寻找 javascript 文件。这需要为每个 JS 文件更新为适当的 URL(例如,从 en 切换到 es 时,将引用从 /en/ 更新为 /es/

    【讨论】:

      猜你喜欢
      • 2015-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-30
      • 2020-02-26
      • 1970-01-01
      • 2022-12-10
      • 2016-01-25
      相关资源
      最近更新 更多