本地开发中完全正常,打包发布到线上发现页面在微信登录回调后出现 404
一、怀疑是nginx站点配置文件没有加载最新
尝试解决
- SSH 进服务器查看是否有多个nginx主进程
- 重启nginx
二、怀疑是HBuilder在打包之前没有配置好
尝试解决
- 检查 H5配置
- 源码视图检查 manifest.json
- 路由检查发现 模式是 history:
"router" : { "base" : "/mobile/", "mode" : "history" },
最终解决:配置修改
https://router.vuejs.org/zh/guide/essentials/history-mode.html
如果是子目录需要将根目录改成子目录
nginx
location / {
try_files $uri $uri/ /index.html;
}
apache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>