我并非在等待任何事或任何人,只是静看时间流逝,长夜消弭,太阳升起。 ---《春天的故事》-

序
这一直在研究uni-pay支付,解决了支付宝小程序支付调用问题后;现在解决uni-pay公众号支付history路由,刷新报404解决方法
前提
公众号中uni-pay支付h5的路由模式必须配置为 history,因为微信公众号登录的回调地址不支持 hash 模式
"router": {
"mode": "history"
}

修改路由模式后点击发布

将前端打包好文件上传到服务器;history和hash有最大的区别体现在打开任意二级页面,hash无论怎么刷新都正常,而history刷新出现404;
在阅读uni-app发布web文档中告诉你history模式需要后端配合
(https://uniapp.dcloud.net.cn/quickstart-hx.html#%E5%8F%91%E5%B8%83%E4%B8%BAweb%E7%BD%91%E7%AB%99)

解决
其实就是history模式需要做下伪静态,官方明明可以直接贴出来的 !但是就没得给你提供了vue官方地址,有点让人害怕
https://router.vuejs.org/zh/guide/essentials/history-mode.html
nginx代理
location / {
try_files $uri $uri/ /index.html;
}
Apache代理
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
