gpt4 book ai didi

javascript - 使用 react-router 使用react的 url 的问题

转载 作者:行者123 更新时间:2023-12-04 01:13:14 27 4
gpt4 key购买 nike

我用 react 路由器 dom 在我的 React 项目中,一切都很好,直到我再添加一个 路线 像这样:

<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 path 作为你 index.html 中 bundle.js 的路径。
您应该使用 absolute index.html 中 bundle.js 的路径
像这样的东西:
<script src="/bundle.js"></script>
而不是这样:
<script src="./bundle.js"></script>

关于javascript - 使用 react-router 使用react的 url 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64158499/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com