javascript - 使用 react-router 做出反应的 url 的问题
问题描述
我在我的 React 项目中使用react-router-dom并且一切都很好,直到我再添加一个这样的Route:
<Route path="/edit/:id" component={EditPage}/>
然后我将浏览器中的 Url 更改为http://localhost:8080/edit/123
它不呈现任何内容,并在控制台中显示以下警告:
GEThttp://localhost:8080/edit/bundle.js
[HTTP/1.1 404 Not Found 19ms]
The resource from “http://localhost:8080/edit/styles.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
123
The resource from “http://localhost:8080/edit/bundle.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
123
The resource from “http://localhost:8080/edit/scripts/bundle.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
123
Loading failed for the <script> with source “http://localhost:8080/edit/scripts/bundle.js”. 123:9:1
GEThttp://localhost:8080/edit/bundle.js
[HTTP/1.1 404 Not Found 3ms]
The resource from “http://localhost:8080/edit/bundle.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
123
Loading failed for the <script> with source “http://localhost:8080/edit/bundle.js”.
有人可以帮忙吗???
解决方案
http://localhost:8080/edit/bundle.js
[HTTP/1.1 404 Not Found 19ms]
这似乎表明您relative
在 index.html 中使用路径作为 bundle.js 的路径。
您应该absolute
在 index.html 中使用 bundle.js 的路径
像这样的东西:
<script src="/bundle.js"></script>
而不是这样:
<script src="./bundle.js"></script>
推荐阅读
- python - GCP Datastore Python - InvalidArgument:400 非事务性提交可能不包含影响同一实体的多个突变
- keycloak - Keycloak -> 如何获取附加到单个角色或组的权限
- python - Making a file executable on a by the work place locked Mac
- php - 有没有办法在php中组合两个foreach循环
- arrays - 需要匹配 mongodb 中的数组值并附加到该数组中
- java - java客户端的MQTT SSL连接失败
- spring - 2021年Spring下如何处理报表风格应用中的多个数据源
- next.js - Next.js 12 新的中间件 api 将变量从中间件传递到页面
- python - 如何在终端中使用 gshuf 或 python 随机打乱 mac os 文件夹中的文件?
- linux - 如何通过 awk 和 grep 将文件名添加到提取的行