首页 > 解决方案 > 使用 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”.

有人可以帮忙吗???

标签: javascriptreactjsreact-router

解决方案


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>

推荐阅读