Azure 页面重新加载时出现 Angular 网站问题

标签 angular azure

问题:每当我重新加载除主页面之外的任何页面时,我都会收到 404 Not Found 错误。它仅发生在 Azure 上(本地主机工作正常)。 我正在使用 Angular 5。 这是浏览器在页面重新加载时向我显示的内容: “您要查找的资源已被删除、更名或暂时不可用。”
网站网址:http://learnwithmentor.azurewebsites.net/
网络配置:https://github.com/ss-ita/learnwithmentor-server/blob/master/LearnWithMentor/Web.config

最佳答案

您可能正在使用 Angular 路线,对吗?您需要添加一些 URL 重写,因为 IIS 当前正在检查您的 URL 指向的文件或目录是否存在。因为他们不这样做,所以它会给你一条错误消息。

这将进入您的system.webServer下的web.config:

<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" />
      </conditions>
      <action type="Rewrite" url="/" />
    </rule>
  </rules>
</rewrite>

关于Azure 页面重新加载时出现 Angular 网站问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53539986/

相关文章:

azure - 用于查找 Azure 订阅属性的 API

angular - rxjs combineLatest 和 Anguar2 对 Observable 数组的变化检测

angular - 如何从angular4的表单中删除一个formGroup?

javascript - 避免重新渲染子组件 NgRx - Firestore

Azure "get support request"API

azure - 使用 Azure 门户配置 BGP

angular - pKeyFIlter : NG8007: The property and event halves of the two-way binding 'ngModel' are not bound to the same target

angular - Uncaught ReferenceError : require is not defined at

asp.net-mvc - 在 MVC 文件下载中提供来自另一个流源的流转发对性能是否有危险

c# - Azure Function 表示无法绑定(bind)参数