Pau*_*nek 25 iis publish angular-cli angular
我有简单的angular2-cli应用程序(一页有模型驱动形式 - 不涉及路由器)."ng服务"一切正常.我用ng build --product制作了生产版本.我将所有./dist文件夹内容复制到C:\ inetpub\wwwroot下的新文件夹中.我从IIS管理控制台制作了虚拟应用程序.Defualt应用程序文件是index.html.我浏览到app uri,我只得到"正在加载..."的页面.我尝试没有--product开关(只有ng build)的构建,但结果是一样的.Angular app未加载.是否还需要在IIS上发布角度应用程序?
ulu*_*eyn 33
这是我如何解决这种情况;
ng builddist文件夹base href在index.html中设置/为/yourAliasNameOnIIS使用此web.config将请求重定向到index.html页面
<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="/yourAliasNameOnIIS" />
</rule>
</rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)
将虚拟目录转换为Web应用程序
您还可以使用ng build --deploy-url "/yourAliasNameOnIIS"更改src路径dist/index.html.
我希望它有所帮助!
Jan*_*yen 13
当您打开浏览器的开发工具时,当应用程序尝试下载js,css等文件时,您会看到404消息
您需要将index.html中的基本href设置为
<base href="./">
这将确保基本引用与您的网站在IIS中的位置相关.您还需要使用散列位置策略,否则,IIS将拦截您的ng2路由器URL更改并尝试查找URL的控制器/操作.
在app.module.ts的导入下:
RouterModule.forRoot(routerConfig, { useHash: true })
Run Code Online (Sandbox Code Playgroud)
我已经完成了这两个步骤,所有这些都在使用IIS的Azure VM上完美运行.这样做也意味着您不必将SPA放在根目录上,并且可以让多个SPA快速地彼此相邻运行(在IIS上的不同网站中)
对我来说,这很简单:
这使其更加简单,您无需修改index.html文件:
ng build -prod --base-href
Run Code Online (Sandbox Code Playgroud)
我尝试了下面的方法,它有效。
| 归档时间: |
|
| 查看次数: |
53294 次 |
| 最近记录: |