React:文件名附加到 url

React: Filename appended to url

知道为什么 index.css 会开始在 axios 请求中显示为 :id 吗?

为了部署到 Heroku,我在 React 中设置了一个代理 "proxy": "http://localhost:3001/"。但是,自从在生产环境和开发环境中都设置了代理以来,我在页面刷新调用中的 :id 字段遇到了一个非常奇怪的问题(仅页面刷新)。

无论出于何种原因,index.css 被追加,因此 axios.get(/document/:id) 的正常页面刷新请求会抛出此错误:Proxy error: Could not proxy request /document/index.css from localhost:3000 to http://localhost:3001/ 这就是命中后端的原因:GET /document/index.css 在这个例子中,:id 应该是 params.id.

<Router> 中定义为 /path/:id 的所有路由都会发生这种情况,无论我是硬编码 :id 值还是使用动态值。

当我使用未设置代理且 localhost:3000 被硬编码到所有 axios 路由中的早期版本进行测试时,不会出现此问题。

我很乐意提供更多 explanation/examples。真的在这里挠头,知道发生了什么事吗?非常感谢!

编辑:已请求 Public index.html 文件

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="./index.css" />
  </head>
  <body>
    <div id="dropdown-options"></div>
    <div id="root"></div>
   
  </body>
</html>

我认为您的问题在于您导入 css 文件的方式。

所以尝试链接它,省略 . - <link rel='stylesheet' href='/index.css'

让我知道这是否解决了您的问题