欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue框架下部署上線后刷新報404問題的解決方案(推薦)

 更新時間:2019年04月03日 11:04:38   作者:安靜Eno  
這篇文章主要介紹了vue框架下部署上線后刷新報404問題解決方案,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index\.html$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.html [L]
</IfModule>

nginx配置

location / {
 try_files $uri $uri/ /index.html;
}

vue history模式下nginx配置

服務端nginx的一開始配置如下(假設域名為:xx.xxx.com): [***** ~]# cat /Data/app/nginx/conf/vhosts/xx.xxx.com.conf

server {
     listen 80;

     server_name testwx.wangshibo.com;
     root /Data/app/xqsj_wx/dist;
     index index.html;

     access_log /var/log/testwx.log main;

}

修改如下:

server {
     listen 80;

     server_name testwx.wangshibo.com;
     root /Data/app/xqsj_wx/dist;
     index index.html;
     access_log /var/log/testwx.log main;
     
 ## 注意從這里開始
     location / {
       try_files $uri $uri/ @router;
       index index.html;
     }

    location @router {
      rewrite ^.*$ /index.html last;
    }
}

原生 Node.js

const http = require('http')
const fs = require('fs')
const httpPort = 80
http.createServer((req, res) => {
 fs.readFile('index.htm', 'utf-8', (err, content) => {
  if (err) {
   console.log('We cannot open "index.htm" file.')
  }
  res.writeHead(200, {
   'Content-Type': 'text/html; charset=utf-8'
  })
  res.end(content)
 })
}).listen(httpPort, () => {
 console.log('Server listening on: http://localhost:%s', httpPort)
})

基于 Node.js 的 Express

對于 Node.js/Express,請考慮使用 connect-history-api-fallback 中間件

Internet Information Services (IIS)

安裝 IIS UrlRewrite

在你的網站根目錄中創(chuàng)建一個 web.config 文件,內容如下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
 <system.webServer>
  <rewrite>
   <rules>
    <rule name="Handle History Mode and custom 404/500" stopProcessing="true">
     <match url="(.*)" />
     <conditions logicalGrouping="MatchAll">
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
     </conditions>
     <action type="Rewrite" url="/" />
    </rule>
   </rules>
  </rewrite>
 </system.webServer>
</configuration>

Caddy

rewrite {
  regexp .*
  to {path} /
}

Firebase 主機

在你的 firebase.json 中加入:

{
 "hosting": {
  "public": "dist",
  "rewrites": [
   {
    "source": "**",
    "destination": "/index.html"
   }
  ]
 }
}

最后

給個警告,因為這么做以后,你的服務器就不再返回 404 錯誤頁面,因為對于所有路徑都會返回 index.html 文件。為了避免這種情況,你應該在 Vue 應用里面覆蓋所有的路由情況,然后在給出一個 404 頁面。

const router = new VueRouter({
 mode: 'history',
 routes: [
  { path: '*', component: NotFoundComponent }
 ]
})

總結

以上所述是小編給大家介紹的vue框架下部署上線后刷新報404問題的解決方案(推薦),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!

相關文章

  • Vue.js 實現(xiàn)微信公眾號菜單編輯器功能(二)

    Vue.js 實現(xiàn)微信公眾號菜單編輯器功能(二)

    這篇文章主要介紹了Vue.js 實現(xiàn)微信公眾號菜單編輯器功能,非常不錯,具有一定的參考借鑒價值,需要的朋友參考下吧
    2018-05-05
  • Vue項目中new?Vue()和export?default{}的區(qū)別說明

    Vue項目中new?Vue()和export?default{}的區(qū)別說明

    這篇文章主要介紹了Vue項目中new?Vue()和export?default{}的區(qū)別說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • 深入解析Vue中的this.$forceUpdate()的使用

    深入解析Vue中的this.$forceUpdate()的使用

    this.$forceUpdate()?是一個重要的實例方法,本文主要介紹了深入解析Vue中的this.$forceUpdate()的使用,具有一定的參考價值,感興趣的可以了解一下
    2024-07-07
  • 基于iview-admin實現(xiàn)動態(tài)路由的示例代碼

    基于iview-admin實現(xiàn)動態(tài)路由的示例代碼

    這篇文章主要介紹了基于iview-admin實現(xiàn)動態(tài)路由的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-10-10
  • element?upload?鉤子函數(shù)的坑及解決

    element?upload?鉤子函數(shù)的坑及解決

    這篇文章主要介紹了element?upload?鉤子函數(shù)的坑及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • Vue.directive使用注意(小結)

    Vue.directive使用注意(小結)

    這篇文章主要介紹了Vue.directive使用注意(小結),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-08-08
  • webstorm+vue初始化項目的方法

    webstorm+vue初始化項目的方法

    今天小編就為大家分享一篇webstorm+vue初始化項目的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-10-10
  • vue中如何使用vue-baberrage生成彈幕

    vue中如何使用vue-baberrage生成彈幕

    這篇文章主要介紹了vue中如何使用vue-baberrage生成彈幕,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • 淺談vue3在項目中的邏輯抽離和字段顯示

    淺談vue3在項目中的邏輯抽離和字段顯示

    本文主要介紹了vue3在項目中的邏輯抽離和字段顯示,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • 淺談Vue頁面級緩存解決方案feb-alive (下)

    淺談Vue頁面級緩存解決方案feb-alive (下)

    這篇文章主要介紹了淺談Vue頁面級緩存解決方案feb-alive(下),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-04-04

最新評論