javascript - 即使配置了 web.config,Angular 7 应用程序刷新也无法在 IIS 上运行
问题描述
我的 Angular 7 应用程序有一个奇怪的行为。每次我点击刷新时,它都会丢失路线并给我一个 404。我在很多地方都阅读过有关配置 web.config 以解决问题的信息,但即使配置了它,我也无法摆脱这个行为。
网络配置
<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="/" />
</rule>
</rules>
模块配置
@NgModule({
imports: [
AppRoutingModule,
SharedModule,
HttpClientModule,
AuthModule,
StoreModule.forRoot(reducers, { metaReducers }),
EffectsModule.forRoot(effects),
StoreRouterConnectingModule,
environment.development ? StoreDevtoolsModule.instrument() : []
],
declarations: [AppComponent],
providers: [
{ provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
{ provide: RouterStateSerializer, useClass: CustomSerializer }],
bootstrap: [AppComponent]
})
export class AppModule {}
<base href="/" />
我的 index.html 文件的标题中也有此部分
解决方案
在文件夹 dist 中,您应该有一个带有项目名称的文件夹尝试将该文件夹的内容直接移动到 dist 下方
推荐阅读
- ruby-on-rails - 设计:确认期结束后注销用户
- flutter - 在 Jenkins 上 Flutter 分析结果
- grpc-python - python grpc客户端支持重试吗?
- php - 带有长 html 内容的 Shopify PUT API 调用
- swift - 如何创建浮动标签栏 Swift
- flutter - 未处理的异常:无效参数(scheduledDate):必须是未来的日期:“TZDateTime”的实例
- c++ - WM_MOVING,LPARAM 在气动快照上给出错误的值
- c# - 使用事件处理程序时抛出异常“在前一个操作完成之前在此上下文上启动了第二个操作”
- android - Intent 广播已通过系统广播超时
- sql - SQl根据参考表计算列值