我有一个简单的应用程序,其中只有一个组件,它希望从URL中获取特定参数。 应用程序中只有一个路由:
const appRoutes: Routes =
path: 'hero/:userId/:languageId',component: HeroWidgetComponent }];
在 Index.html 文件中,我在头部有这样一行代码:<base href="/">
我正在使用 webpack,在开发环境下运行正常,可以通过以下 url 进行访问:http://localhost:4000/hero/1/1
.
然而,当我打包应用并将其放到 IIS 上托管时,尝试浏览相同的 url 时出现以下错误:
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
如果我删除所有路由并只浏览以下内容:http:localhost:4200
,该应用程序可以正常工作。
IIS
服务器需要正确配置,以便将所有的 Angular 路由重定向到index.html
(或触发 Angular 应用的 HTML 文件)。不幸的是,我不是IIS
服务器专家,所以我无法给出确切的答案来解决这个问题。 - tftd