为什么 React 生产构建只显示 404 页面而没有页面的其余部分?

why React production build only shows the 404 page without the rest of the page?

我用 React 创建了一个网站,我正在使用 react-router-dom 我想将它部署到 netlify,所以我 运行 npm 运行 build 但是当我单击 index.html。它只显示我为不存在的路径创建的路由,即 404 页面,如何显示主页和页面的其余部分?

netlify.toml 文件添加到项目的根目录并添加以下行。然后 re-deploy 在 Netlify 上。

Redirects and rewrites

这是指示 netlify 将所有路由重定向到您的应用所必需的。这样 react-router-dom 可以在内部处理路由。

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200