在我的Angular 4应用程序中,如果我在第一次访问该站点时键入了一个非根路径(即localhost:4200 / projects),我的应用程序将被引导并且正确的组件将呈现在浏览器的屏幕上.
但是,一旦我通过IIS提供网站,如果我转到http://< my-domain> .com / projects,我会收到404错误(不是来自我的应用程序),并且应用程序永远不会被引导.
作为第一次访问生产中的站点,我如何访问非根路径,以识别该应用程序是一个Angular应用程序并为任何根路径或更远的路径引导应用程序?
有关发生这种情况的更详细说明,请参见
my answer here.
一个简短的片段:
一个简短的片段:
On the deployed version of your app,the web server hosting it kNows
only how to serve the one html file it sees (index.html),which
corresponds to your root path. The second you try to access directly
07001 for example,the server will throw a 404
not found,as it does not recognize that as the path of a resource it
can serve.
对于IIS,解决此问题的最简单方法是将其添加到web.config:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <httpErrors> <remove statusCode="404" subStatusCode="-1" /> <error statusCode="404" path="/index.html" responseMode="ExecuteURL" /> </httpErrors> </system.webServer> </configuration>
这样做是指示IIS在检测到404时使用index.html进行响应.
原文地址:https://www.jb51.cc/angularjs/142484.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。