Nginx配置ReactJs项目,Url后面直接输入路由路径时老报404问题。

xiaoxiao2021-02-28  91

当我们写完项目后,要对项目进行部署,我的配置很简单

location /demo { root E:/; index index.html index.htm; }

这样配置的有一个问题,只能 http://localhost/demo/来访问。 如果想访问里面的其它界面如 http://localhost/demo/page1的话,就报404找不到页面。 可我在开发的时候,确实没有问题,可以进行访问的,于就想难道必须得用node来项目吗?不会吧,也许是我自己不会配置所致。 终于找到办法了,在其它人的nginx.config里发现多加了一行东西。

location /demo { root E:/; #加上了这个,就可以在url后面直接加路由上配置path了。 try_files $uri /demo/index.html; index index.html index.htm; }

致于为什么,不清楚,但是功能实现了。

在此标记一下,以备后需之用。

转载请注明原文地址: https://www.6miu.com/read-35175.html

最新回复(0)