我正在嘗試在 IIS 上部署 VUE 前端應用程式。
路由在開發模式下作業正常,但是,當我在 IIS 上托管我的 VUE 應用程式時,路由似乎中斷了。有人可以建議如何配置 IIS 來處理 VUE 前端應用程式的路由(我正在使用 vue-router)?
uj5u.com熱心網友回復:
以下是使用正確的路由配置在 iis 服務器上部署 vue 應用程式的步驟:
設定 IIS
- 下載并安裝:
.NET Core Hosting Bundle
Microsoft URL Rewrite - 重新啟動 IIS 服務。
- 右鍵單擊站點檔案夾并選擇“添加網站”
→ 輸入站點名稱(例如 myWebsite)
→ 創建一個檔案夾(您的網站檔案所在的位置)并輸入檔案夾的路徑作為網站物理路徑。
生成 VUE 應用程式檔案
- 轉到專案檔案夾并運行命令:
npm run build - 將生成的“dist”檔案夾中的檔案粘貼到您網站的物理路徑中。
- 將“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>
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="404" path="/survey/notfound" responseMode="ExecuteURL" />
<error statusCode="500" path="/survey/error" responseMode="ExecuteURL" />
</httpErrors>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/370448.html
