【问题标题】:Why does my React app say 404 not found when I refresh a page?为什么我的 React 应用程序在我刷新页面时显示 404 未找到?
【发布时间】:2021-01-13 15:38:30
【问题描述】:

我在 AWS EC2 实例中使用 Nginx 部署了一个 React 应用程序,当我使用导航栏打开页面时它运行良好。

但是当我刷新一个页面时,它说 404 not found 即使它在导航中正常工作。

前端(React)和后端(Node)服务都在服务器中运行。

我的 Nginx 配置如下。

【问题讨论】:

  • 您需要在后端设置一条全部路径。喜欢app.get('*', function(req, res) { // copy paste the root path code here });。使用react-router 之类的前端导航和直接点击后端路由(比如刷新页面或在地址栏中手动输入地址并点击回车)不是一回事。
  • 你有 web.config 吗?
  • 类似的事情发生在我身上 - 在 Azure Web App 上。看看这个 - stackoverflow.com/questions/64051157/… 。可能是应用配置问题
  • @EranAmarante,我没有使用 IIS,所以它没有 web.config。

标签: node.js reactjs amazon-ec2 uinavigationbar page-refresh


【解决方案1】:

这是我在 Node 后端的 index.js 路由。 并将其导入到根文件夹中的app.js

var indexRouter = require('./routes/index');

Jade 已安装,但从未使用过。 请让我知道此问题的任何更新。

【讨论】:

    猜你喜欢
    • 2020-01-16
    • 2019-11-01
    • 2021-01-08
    • 2021-11-26
    • 2022-07-01
    • 2020-09-22
    • 1970-01-01
    • 2021-08-15
    • 2011-01-12
    相关资源
    最近更新 更多