一:nginx服務器解決方案,修改 .conf 配置文件
有兩種解決方案
1:
location / { try_files $uri $uri/ @router; index index.html; } location @router { rewrite ^.*$ /index.html last; }
2:
location / { error_page 404 /index.html; #try_file $uri $uri/ /index.html =404; }
二:apach服務器解決方案
(假設放在csdn目錄下)分以下幾步
1.配置路由:使用history模式,并且配置base
2.在config/index.js文件里的assetsPublicPath改成你放在服務器的文件路徑里,根目錄就是‘/" 如果是放在某個文件夾,例: /csdn/‘"
3.修改Apache的httpd.conf文件,使其支持 .htaccess ,
4.在對應的文件夾項目下添加.htaccess文件,(這里需要注意的是因為windows不支持無文件名的格式 即 .***, 所以需要先新建一個文本文檔,把內容寫好,然后ftp上傳到對應目錄,然后重命名,這里重命名后會看不到,需要把ftp設置為可以查看隱藏文件)
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /csd/ RewriteRule ^index.html$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /csd/index.html [L] </IfModule>
5.重啟服務器
總結
到此這篇關于vue打包上傳服務器刷新404問題的兩種方案的文章就介紹到這了,更多相關vue打包上傳服務器404內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文鏈接:https://blog.csdn.net/ahzhaihui/article/details/82217604