移入IIS虚拟目录时,Angular 2应用程序无法正常工作

时间:2017-03-25 13:51:34

标签: angular iis angular2-routing

我在本地PC上的IIS(inetmgr)上创建了一个虚拟目录,然后将其转换为IIS Web应用程序。 Web应用程序的根目录是:http://localhost/xyz/部署并运行应用程序时,我在浏览器中收到以下错误:

  

找不到所有html组件404错误。

在web.config中添加了重写规则。我将index.html的基本href更改为./xyz或./但没有运气。

如果我将它部署到根目录,一切都会解决 - 不确定出了什么问题。

1 个答案:

答案 0 :(得分:1)

1。启用xyz文件夹作为Web应用程序文件夹(见下图)

2。更新基本href,例如<base href="/spa/">

3。设置重写规则

<rewrite>
  <rules>
    <rule name="Angular Routes" stopProcessing="true">
      <match url=".*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
      </conditions>
      <action type="Rewrite" url="/" />
    </rule>
  </rules>

希望它有所帮助!