react-router 中 history
- browserHistory
- hashHistory
hashHistory 路径会带#
browserHistory get请求时会走服务端,服务端只对 / 路径做处理返回 index.html ,当请求其他路径时找不到匹配返回 404
所以使用 browserHistory 时,需要当访问其他路径时,服务端也返回 index.html,然后由单页面应该自己匹配路由信息
当使用 nginx 部署
location / {
try_files $uri /index.html;
root /dist;
index index.html;
}
当使用 node 如 koa 部署
可以使用 koa2-history-api-fallback 中间件处理