我已经部署了以前工作良好的角应用程序,但是当我将应用程序的内部组件放到根模块并试图从应用程序的顶部访问它时,它会在IIS上抛出这个错误。
这是我的角路由文件:
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},
]
}];
发布于 2019-08-08 10:42:48
替换
<action type="Rewrite" url="./index.html" />使用
<action type="Rewrite" url="/" />发布于 2021-06-22 08:04:09
我在chrome中得到了相同的错误,但是我尝试在firefox中打开它,而实际的错误是iis被配置为禁用双重转义序列,所以我设置了配置请求筛选以允许双重转义。
<security>
<requestFiltering allowDoubleEscaping="true" />
</security>然后它就能工作了,但是要注意这个解决方案将添加的security holes。
发布于 2021-07-10 01:05:05
对于IIS,在Web.config中添加重写规则。
只需将Web.config放在应用程序的根文件夹中即可。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="AngularRewrite" 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="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>如果您很不幸并且无法添加该HashLocationStrategy,请使用Web.config作为最后的手段。
https://stackoverflow.com/questions/57410678
复制相似问题