【发布时间】:2019-08-08 10:38:44
【问题描述】:
我已经部署了以前运行良好的 Angular 应用程序,但是当我将应用程序的内部组件放到根模块并尝试从应用程序顶部访问它时,它会在 IIS 上引发此错误。
这是我的 Angular 路由文件:
export const routes: Routes = [
{ path: 'enable-cookies', component: EnableCookiesComponent },
{ path: 'not-found', component: NotFoundComponent },
{ path: 'lock-screen', component: LockScreenComponent, canLoad:
[RestrictPathGuard] },
{ path: 'booking-detail/:id/:id2', loadChildren:
'./public/public.module#PublicModule'},
{ path: '', loadChildren: 'app/components/pages.module#PagesModule',
canActivate: [UserProtectionGuard] },
{ path: '**', redirectTo: 'not-found' }
];
在上述路线中,路径 booking-detail/:id/:id2 给了我 404 错误,其他路径工作正常。
我在下面的 web.config 中也有我的 url 重写文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Angular Routes" 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="./index.html" />
</rule>
</rules>
我有什么遗漏或做得不对吗?
以下是我正在尝试访问的网址。
http://10.1.1.1:7070/booking-detail/MTk2NnwxMDR8U0VBfEdVRVNU/Dm9duQS%2fI%2fZSLdXyQTyLVZUNRjuTxRjXhGUxecdVifZh%2fhk6cWKIH6chi5pQgr6e3HQ296gGFgRE%2fkpFoW95YgsFCWQuSdeKk79iPFi9RW1RFQfZ4Zr%2fQYZ40r0q%2bzBuDZmVrrxU39Ayn9nGP5%2fNbD7219uff8K5cwsTYkhqxNDjbfZ5SHcPiPXvdyRkDnFpXzsmNq0TjOAPIBqsRkVilmFCWI6tYCxx4brwKO7Acy1EE8TD3p9U6BS%2fZLhZikFkiAhHUKVw8ImLGhctp5TDfg3BIYHMQ7Rj4BEYnEEdpxxRP%2fgB3g%2bvRB4l8sCgJSCc4SVrQIb68lXttzfyEDLLJIzmCVdRDoCnRUqRMuJWSzXQ5m0vcvEhP1p%2bpdSp7OwJQag82YlO%2fv0lIkrSvrMih4auBjEv64%2fFJfYJ7dK%2fGOmBHuh5ET7du13kpKql7k39LrRR4BkzQS4cCswuD8PS6w%3d%3d
这里是PublicModule的路由
export const routes: Routes = [
{
path: '',
component: PublicComponent,
children: [
{ path: '', component: ViewBookingComponent},
]
}
];
【问题讨论】:
-
你的 index.html 中有
吗? -
@SGalea 是的,我的 index.html 标签中有那个标签
-
能把PublicModule的路由加到问题里吗?我认为这不是 IIS 问题,因为您设法在之前部署了它,但是 rewrite 应该是 url="/" 和 base href='/' 您的问题与路由有关。
-
@SGalea 我添加了公共模块路由
-
我已经用这种路由结构进行了测试,它正在工作,但我没有看到自己的想法。我的建议是添加一个按钮,看看通过角度路由与 URL 直接访问是否有效。还要在文本编辑器中打开已部署的 web.config 和 index.html,如果您正在使用某些部署自动化,请查看它是否是您打算部署的内容。 (永远不能太确定)