首页 > 解决方案 > Azure 在页面重新加载时出现 Angular 网站问题

问题描述

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

标签: angularazure

解决方案


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

这进入你的web.configsystem.webServer

<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>

推荐阅读