在React项目中我们经常需要采用React-Router来配置我们的页面路由,React-Router 是建立在 history 之上的,常见的history路由方案有三种形式,分别是:
1.hashHistory
2.browserHistory
3.createMemoryHistory
如果使用hashHistory
,访问的页面url如 example.com/#/some/path
的路由。
于是采用第二种browserHistory,但是部署到自己的服务器之后,可以正常访问,但是强制刷新页面之后报404找不到页面路径
Nginx配置方式如下
server { server_name react.thinktxt.com; listen 80; root /Users/txBoy/WEB-Project/React-Demo/dist; index index.html; location / { try_files $uri /index.html; } }
访问后刷新,解决404问题