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 中間件處理