我们开发了 Angular2 应用程序。
当我们在 Angular-cli 下使用“ngserve”运行时,它工作正常。
一旦我们将应用程序托管到 IIS 7.5,我们就可以浏览到应用程序的根目录,而不会出现太多问题,并且我们可以从创建的应用程序导航中导航到任何其他视图。
但是,当用户尝试加载针对特定路由或组件的 url 时,问题就会出现。
所以如果我们去http://服务器地址...它加载索引.html然后单击 index.html 上的导航链接,用户将进入http://serverurl/route1/component1
但是当用户尝试访问 url 时http://serverurl/route1/component1直接输入http://serverurl/route1/component1在浏览器地址栏中,它将该请求发送到 IIS,然后返回错误并提示找不到资源。
而且很容易理解,该 url 在服务器上不存在。那是角度网址。理想情况下,它应该加载索引.html并将其余的 url 传递给 Angular 路由器并加载/路线1/组件1。这适用于“ngserve”,但不适用于 IIS 7.5。我需要在 IIS 中进行任何设置才能使其正常工作吗?或者我必须在 Anuglar2 应用程序中做任何事情?
谁能建议我如何解决这个问题?
我通过执行以下步骤解决了这个问题..
已下载网址重写器模块来自https://www.microsoft.com/en-au/download/details.aspx?id=7435
在我的 web.config 中添加了以下内容
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="AngularJS" 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>
</system.webServer>
</configuration>
- 在index.html 中设置基本标签。应该是紧接着 tag
这三个步骤将为您的部署做好准备Angular2 / Angular 应用程序 with HTML5模式 url on IIS 7.5 或 IIS 8.0
希望这会有所帮助。我必须通过几个答案才能解决这个问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)