解决IIS+vue 在地址栏直接输入URL报404的问题

1. vue-router 设置 history 模式

2. IIS 配置

  1. 安装 url rewrite https://www.iis.net/downloads/microsoft/url-rewrite
  2. 在网站根目录下添加 web.config
       <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <rewrite>
        <rules>
            <rule name="API Rule" stopProcessing="true">
                <match url="^(api|account|manage)(.*)$" />
                <action type="None" />
            </rule>
            <rule name="Angular Rule" 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>
  </location>
</configuration>
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容