angular - 部署到 IIS 的 Angular 脚本出现 404 错误
问题描述
我已经在 Windows Server 上向 IIS 部署了一个 Angular 应用程序,但由于脚本/样式包都给出 404 错误,它无法加载。我在 IIS 中将我的应用程序设置为“门户”,并在 web.config 中完成了 URL 重写:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<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="/portal" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
并将 index.html 上的基本 url 设置为:
<base href="/portal">
当我将应用程序构建到 dist 文件夹时,我使用的命令只是一个简单的构建ng b
,没有任何选项。
我在控制台中遇到的错误示例是:
GET http://wavemaker.webdevelopwolf.com/inline.bundle.js net::ERR_ABORTED 404 (Not Found)
解决方案
要构建应用程序,请使用命令
ng b --deploy-url /portal/
推荐阅读
- android - 我需要一个可以动态添加图标并将它们放在某些位置的工具栏
- javascript - Javascript 排序数组 ERROR TypeError: undefined is not an object
- swift - 应用程序在模拟器中崩溃,而不是在用于转换日期格式的设备上
- python-3.x - 如何在 init() 中保存用户输入字符串
- windows - 从命令行强制刷新(重新扫描)无线网络?
- reactjs - componentWillUnmount 什么时候真正触发
- java - 游标因 CursorIndexOutOfBoundsException 而崩溃
- ruby - 如何从 Ruby 2.4 中的哈希生成可靠的摘要?
- mysql - 如何在 MySQL 5.7 中组织这个查询?
- r - 在 ggplot2 中使用 scale_color_manual 时,绘图中的中断和值不匹配