问题描述
在本地用vue搭建前端测试正常,将dist文件夹抛到服务器端,访问出现跳转页面显示404报错的异常
问题解决
详见Error 404 on reload or direct URL with Vue and Apache
That is due to the history push mode on your vue router. https://router.vuejs.org/guide/essentials/history-mode.html
If your Apache version is above 2.2, you can use Fallback ressource instead of mod_rewrite in your apache config. It works for me.
In /etc/apache2/apache2.conf
<VirtualHost *:80>
ServerName YourServerName(like yourwebsite.com)
DocumentRoot /var/www/yourAppLocation/dist
<Directory "/var/www/yourAppLocation/dist">
FallbackResource /index.html
</Directory>
</VirtualHost>