我正在尝试使用 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确实有效,但在远程虚拟机上它也不起作用。
添加回答
举报
0/150
提交
取消