使用react路由器react中实例的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的路径

您应该在index.html 中使用bundle.js的absolute路径

类似这样的东西:

<script src="/bundle.js"></script>

不是这样的:

<script src="./bundle.js"></script>

I将<base href="/" />添加到html文件的head标记中,它就工作了。

相关内容

  • 没有找到相关文章

最新更新