html - 从 netlify 托管的我的 reactjs 中的链接断开

标签 html css reactjs netlify

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

最佳答案

您似乎在站点内使用 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

关于html - 从 netlify 托管的我的 reactjs 中的链接断开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61025635/

相关文章:

html - 如何使显示 : table-cell be 100% 内的 <div> 的高度

JavaScript 脚本引用系统

javascript - 如何在右箭头单击时将表格水平滚动到最后一个 td?

javascript - 如何根据 CSS 中的屏幕大小更改文本(不是字体大小)?

javascript - react 模态滚动到顶部

javascript - react : Filter multidimensional array object by value in component

javascript - 如何将javascript转换为Winjs

jquery - 使 <div> 的边框与 .left 位置对齐

css - 使用 JavaFX 8 和 css 加载自定义字体

javascript - 我可以在 PureComponent 中使用 shouldComponentUpdate