原因
是由于使用vue-router的 history 模式,这种模式充分利用 history.pushState API 来完成URL跳转而无须重新加载页面。
mode: 'history'
解决方案
在服务端增加一个覆盖所有情况的候选资源(如果 URL 匹配不到任何静态资源,则应该返回同一个 你 app 依赖的页面index.html):
在项目目录下新建文件.htaccess文件,添加内容:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>