国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

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

2024-05-06 15:41:06
字體:
來源:轉載
供稿:網友

<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 = 80http.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

在你的網站根目錄中創建一個 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 頁面。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 开远市| 竹山县| 宁远县| 开封县| 宁国市| 广南县| 新田县| 深水埗区| 韶山市| 张北县| 大田县| 义马市| 镇康县| 苍山县| 正阳县| 鹤壁市| 姜堰市| 鄂伦春自治旗| 祁东县| 嘉黎县| 双城市| 普宁市| 农安县| 若尔盖县| 晋州市| 甘南县| 亳州市| 类乌齐县| 门头沟区| 繁峙县| 涞水县| 敦煌市| 花莲县| 科尔| 西华县| 临城县| 高安市| 班戈县| 革吉县| 重庆市| 抚松县|