Angular项目在IIS中浏览时,当页面刷新时会出现404页面,这是因为Angular无刷新的特性引起的,在浏览器地址栏的网址不会真实映射到磁盘的特定位置。
解决方案:
1.安装URL rewrite组件
2.在index.html目录下 添加web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/x-javascript" />
</staticContent>
<rewrite>
<rules>
<rule name="AngularJS" 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>
其中,staticContent 节点,配置MIME类型,使.JSON文件能被正确解析
网友评论