nginx配置(解決vue項目發佈新版本後出現短暫白屏問題 | 解決vue-router切換爲history模式後刷新頁面出現404問題)

#爲了解決線上發佈新版本後訪問前端頁面出現短暫性白屏問題,就是把緩存給禁用掉
location = /index.html {
   add_header Cache-Control "no-store, no-cache, no-transform, must-revalidate, max-age=0";
}

location / {
   try_files $uri $uri/ @router;#需要指向下面的@router否則會出現vue的路由在nginx中刷新出現404
   index  index.html index.htm;
}
#對應上面的@router,主要原因是路由的路徑資源並不是一個真實的路徑,所以無法找到具體的文件
#因此需要rewrite到index.html中,然後交給路由在處理請求資源
location @router {
   rewrite ^.*$ /index.html last;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章