我正在尝试使用gulp在system js builder的帮助下捆绑一个Angular 2应用程序。我接下来大多是用https://github.com/smmorneau/tour-of-heroes写的。我能够创建捆绑包。创建捆绑包后,我尝试在IIS中将应用程序部署为默认网站下的Web应用程序。
在我的应用程序中,我已将模板和css放在相应的组件文件夹中。但是在应用程序启动期间,我的html模板没有被加载,因为url不包含虚拟目录名并导致404.例如。 http://localhost/app/app.component.html应为http://localhost/Angular2Test/app/app.component.html。我的捆绑app.min.js请求此网址为xhr请求。为了解决正常的请求,我有IIS重写规则,如下所示
<system.webServer>
<rewrite>
<rules>
<rule name="angularjs routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/Angular2Test/" />
</rule>
</rules>
</rewrite>
</system.webServer>
有人可以帮我这个吗?我是否需要在Angular2端设置一些基本路径或其他东西。我已将我的示例上传到GitHub https://github.com/sajanep/Angular2PackagingTrial。
答案 0 :(得分:0)
我认为你需要
<base href="/someDir/">
添加到<head>
元素{provide: APP_BASE_HREF, useValue: '/someDir'}