You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular路由刷新后资源文件路径错误问题求助

解决方案

方法一:改用绝对路径引用脚本

将index.html中的脚本路径修改为以斜杠开头的绝对路径,强制浏览器从域名根目录加载资源:

<script src="/assets/adminlte/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>

方法二:通过Angular配置统一管理脚本

  1. 打开angular.json,找到projects.Portal.architect.build.options.scripts数组,添加目标脚本的相对路径:
"scripts": [
  "src/assets/adminlte/plugins/bootstrap/js/bootstrap.bundle.min.js"
]
  1. 删除index.html中手动添加的<script>标签。
    这种方式由Angular构建工具自动处理路径映射,彻底避免路由层级导致的资源定位错误。

额外验证:确认base href配置

检查index.html的<head>区域是否包含正确的base标签,这是Angular路由正常运行的基础:

<base href="/">

默认Angular项目会自动生成该标签,若缺失请手动补充。

内容的提问来源于stack exchange,提问作者ilker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 08:50:16