azure - 需要修复在 Azure 应用服务上运行的 Angular 2 的路由问题

标签 azure angular azure-web-app-service

我有一个基于 Angular 2 "Tour of Heroes" Quick Start 的 Angular 2 网站.

本地运行时工作正常。修复问题以不再使用本地 node_modules(根据快速入门中的 deployment steps)并部署到 Azure Web 应用程序后,如果我从根 URL(“/”)开始,该应用程序可以正常工作。但是,使用 Angular 路由,URL 会发生变化(例如更改为“/home”),并且如果我对该 URL 执行 F5 刷新,则应用程序将无法加载。当我这样做时,我得到一个 404:

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

我尝试按照描述使用 web.config here但这没有帮助。看起来确实是 IIS 问题,它尝试提供页面而不是从 index.html 开始。我的路线是在 Angular 中定义的,并且它们在本地工作。

最佳答案

你能试试这个 web.config 文件吗

<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" />
                </conditions>
                <action type="Rewrite" url="/" />
              </rule>
            </rules>
          </rewrite>
          <caching enabled="true" enableKernelCache="true">
              <profiles>
                  <add extension=".js" policy="DisableCache" kernelCachePolicy="DisableCache" />
              </profiles>
          </caching>
    </system.webServer>
</configuration>

关于azure - 需要修复在 Azure 应用服务上运行的 Angular 2 的路由问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42321275/

相关文章:

azure - 间歇性 Azure 模拟器错误 : Could not load file or assembly 'XX' The filename or extension is too long.

azure - 存储和事件网格之间的弹性

javascript - 无法从 Angular 5 和 Dragula 制作多个内部可拖动对象

javascript - HighCharts 数据结构 - 多个独立系列、堆积柱形图

asp.net-mvc - Azure 网站呈现问题

azure - 您可以在不部署整个网站的情况下替换 Azure 网站中的选定文件吗?

azure - 如何在 Application Insights 中查看日志?

azure - Azure Golang函数不在正文中接收请求有效负载

Angular 6 子路由不起作用

Azure:如何在不重新启动应用程序服务的情况下重新加载环境变量