问题:每当我重新加载除主页面之外的任何页面时,我都会收到 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/