从 netlify 托管的我的 reactjs 损坏 link

Broken link in my reactjs hosted from netlify

我最近通过 github 在 Netlify 中托管,我的网站是从 reactjs 呈现的。我的网站 link 是 https://realhomes.netlify.com/ 。因此,当我尝试从主页(索引页)以外的其他页面重新加载我的网站时,它显示损坏 link,我不知道如何修复它。请帮忙

您似乎在站点内使用 react-router 在不同页面之间进行路由。如果是这种情况,您需要告诉 Netlify 为所有内容提供 index.html 文件,而不仅仅是网站的根目录。

来自this netlify blog post

If you choose to use something for routing (like React Router for example), you will need to set up a redirect and rewrite rule for the single page app.

尝试将 /* /index.html 200 添加到发布目录中的 _redirects 文件或将以下内容添加到 netlify.toml.

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

Read the docs here

如果有人想知道 netlify.toml 文件的样子,您可以在我的 github 存储库在 Link Here 中并且有效。

在 public 文件夹中创建 _redirects 文件并添加 /* /index.html 200,现在您的应用程序不会在刷新时崩溃。