一、問題描述
開發(fā)過程中,路由可以正常訪問,打包后也可以正常訪問,但是一刷新頁(yè)面就會(huì)出現(xiàn)404錯(cuò)誤
二、解決方案
方法一:修改為Hash路由模式
在router/index.ts文件中,將history路由模式修改為hash路由模式即可。
history路由模式:
history: createWebHistory(import.meta.env.BASE_URL),
hash路由模式:
history: createWebHashHistory(import.meta.env.BASE_URL),
方法二、修改后臺(tái)偽靜態(tài)
Nginx:
location / {
try_files $uri $uri/ /index.html;
}
Apache:文章來源:http://www.zghlxwxcb.cn/news/detail-505792.html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
可以參考下這篇文章《thinkphp6.x+vue3前后端分離項(xiàng)目部署偽靜態(tài)》文章來源地址http://www.zghlxwxcb.cn/news/detail-505792.html
到了這里,關(guān)于vue3.2項(xiàng)目中使用history路由模式刷新后頁(yè)面404的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!