前端spa项目,使用
刷新后页面错误
node 服务器设置
app.use(function(err, req, res, next) { // set locals, only providing error in development res.locals.message = err.message; res.locals.error = req.app.get(‘env‘) === ‘development‘ ? err : {}; //render the error page res.status(err.status || 500); //解决项目部署后刷新错误的问题 res.sendFile(path.join(__dirname,‘public‘,‘index.html‘)) });
nginx 服务器设置
server{ listen 80; server_name location; root yourProject; index index.html index.htm; location / { try_files $uri/ /index.html =404 } location ^~ /api { rewrite "api/(.*)$" /api/$1 break; #proxy_pass proxy_set_header Remote_Addr $remote_addr; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
前端项目路由使用browserHistory不能刷新,页面刷新错误,
原文:https://www.cnblogs.com/anin/p/14607259.html