【问题标题】:Angular 4 IIS routing issueAngular 4 IIS 路由问题
【发布时间】:2017-10-08 01:38:44
【问题描述】:

我已经实现了一个 Angular 4 应用程序并准备好在 Windows Server 2008 R2 上部署到 IIS 7.5,所以只需简化我刚刚使用 Angular CLI 创建一个新的 Angular 4 项目并使用 ng build --prod 构建它。然后在 IIS 中添加了一个名为 AngularApp 的新网站并映射到 C:\Inetpub\wwwroot\AngularApp。我复制了 dist 下的所有文件。我还将 URL 重写添加到 web.config。当我转到 URL http://localhost/AngularApp 时,我看到正在加载...但是应用程序可以工作!从不显示。我知道已经提出了一些类似的问题,但我通过将<base href="/"/> 更改为<base href="/AngularApp/"/> 和 URL 重写来跟踪我在网上找到的所有内容,但似乎没有找到解决方案。 Angular 代码直接来自 Angular CLI,无需修改。不知道我在这里错过了什么......

下面是重写

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
        <rules>
            <rule name="angularjs 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="^/$" negate="true"/>
                </conditions>
                <action type="Rewrite" url="/" />
            </rule>
        </rules>
    </rewrite>
  </system.webServer>
</configuration>

【问题讨论】:

    标签: angular iis-7.5 angular2-routing


    【解决方案1】:

    我找出问题所在。由于我们的服务器只安装了 IE,所以启动了 IE。打开开发人员工具后,我看到我收到 Unable to get property 'apply' of undefined or null reference 错误。我不得不删除 pollyfills.ts 中注释掉的代码以支持 IE11。在那之后,我确实看到了该应用程序的工作原理!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-11
      • 1970-01-01
      • 2018-07-26
      • 1970-01-01
      相关资源
      最近更新 更多