javascript - Html base href 重写在 200 之后获取第一个 404
问题描述
我在 IIS 站点的子目录下有一个 blazor 应用程序。要修复 blazor wasm 基本路径问题,请在 head 标记中应用下面的 javascript 代码(在 elmah.io 上建议:https ://blog.elmah.io/how-to-fix-blazor-wasm-base-path-problems/ )
<!-- omitted for clarity -->
<head>
<base />
<script>
var path = window.location.pathname.split('/');
var base = document.getElementsByTagName('base')[0];
if (window.location.host.includes('localhost')) {
base.setAttribute('href', '/MyApp/');
} else if (path.length > 2) {
let href = '/' + path[1] + '/MyApp/';
base.setAttribute('href', href);
} else if (path[path.length - 1].length != 0) {
let fullpath = window.location.origin + window.location.pathname + '/' + window.location.search;
window.location.replace(fullpath);
}
</script>
</head>
它工作得很好,解决了 blazor 基本路径问题。但是,当您输入不以“/”结尾的应用程序 url 时,开发人员控制台会填满 404(未找到)错误,然后对于所有 css/js 文件,所有错误都会显示为 200(ok)ok。为什么会这样,我可以修复它吗?
解决方案
推荐阅读
- typescript - TypeScript 模块导入路径映射
- java - 如何从具有动态条目的文件中拆分
- sparql - 可靠地查询 SPARQL 端点并在本地缓存结果
- c# - 动态组合框参数重置
- identityserver4 - 调用 /connect/userinfo 返回错误“未处理的异常:序列包含多个匹配元素”
- tensorflow - tensorflow 中 Masking() Keras 函数的等价性是什么?batch norm、conv 和 relu 是否支持 Masking?
- asp.net - Windows 身份验证不适用于 IIS Express 10
- unit-testing - 测试在 Golang 中加载 JSON 配置文件的方法
- select - 将数据从 mongo 加载到选择元素中
- regex - 如何从 Scala 中的字符串中删除所有尾随反斜杠?