为了账号安全,请及时绑定邮箱和手机立即绑定

使用路由器时,使用 nginx 响应应用程序不切换组件

使用路由器时,使用 nginx 响应应用程序不切换组件

哆啦的时光机 2021-07-12 16:53:55
我正在尝试使用 nginx 部署我的 React 应用程序。我遇到的问题是在更改路由时,例如 /about 它实际上并没有更新前端,它只是保留在索引上。这是我在可用站点中的配置:server {  listen 80 default_server;  server_name server_ip_here;  root /sites/FrontEnd/React/build;  index index.html;  access_log /var/log/nginx/krim.com.access.log;  error_log /var/log/nginx/krim.com.error.log;  location / {      try_files $uri /index.html;  }}这是路由器:import {Redirect, BrowserRouter as Router,Route,Switch} from 'react-router-dom';<Router>      <CookieConsent buttonText="Accept">      </CookieConsent>      <Switch>        <Route exact path="/" component={Home} />        <Route path="/About" component={Over}/>        <Route path="/FAQ" component={FAQ}/>      </Switch></Router>现在,页面索引已加载,但在使用 nginx 时转到 my-ip/About 或 my/FAQ 不会执行任何操作。现在使用npm start它一切正常,而且使用serve -s build也很好,所以这似乎是我的一些 nginx 配置错误。任何帮助表示赞赏,干杯。编辑:更正,本地serve确实有效,但在远程虚拟机上它也不起作用。
查看完整描述

2 回答

?
茅侃侃

TA贡献1842条经验 获得超21个赞

我在自己的电脑上构建了这个包,然后将它上传到虚拟机,现在它可以正常工作了。


查看完整回答
反对 回复 2021-07-15
  • 2 回答
  • 0 关注
  • 184 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信