Vite+Vue3佈署上IIS重新整理頁面發生404之解法


Posted by hotmaneil on 2024-08-30

最近專案Vite+Vue3佈署上IIS重新整理頁面會發生404,因此記錄下來解法:

第一種解法:
router/index.ts

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: []
})

改為

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: []
})

第二種解法:
在public下新增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>

只能選一種解法,同時用的話會出錯


#vue3 #iis







Related Posts

[SQL] Want to declare a string array variable? Declare a table variable instead.

[SQL] Want to declare a string array variable? Declare a table variable instead.

[第七週] 改變元素

[第七週] 改變元素

99乘法表變化版

99乘法表變化版


Comments