首页 > 解决方案 > 即使配置了 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 文件的标题中也有此部分

标签: javascriptangulariisrouting

解决方案


在文件夹 dist 中,您应该有一个带有项目名称的文件夹尝试将该文件夹的内容直接移动到 dist 下方


推荐阅读