【问题标题】:Angular 7 app refresh not working on IIS even with web.config configured即使配置了 web.config,Angular 7 应用程序刷新也无法在 IIS 上运行
【发布时间】:2019-04-17 16:31:14
【问题描述】:

我的 Angular 7 应用程序有一个奇怪的行为。每次我点击刷新时,它都会丢失路线并给我一个 404。我在很多地方都阅读过有关配置 web.config 以解决问题的信息,但即使配置了它,我也无法摆脱这个行为。

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 {}

我的 index.html 文件的标题中也有这部分 &lt;base href="/" /&gt;

【问题讨论】:

    标签: javascript angular iis routing


    【解决方案1】:

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

    【讨论】:

    • 我正在向我的 IIS/Azure 发布此文件夹的内容(带有我的项目名称的那个)。在我的开发机器中,当我通过ng s 启动应用程序时,一切正常
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-09
    • 1970-01-01
    • 1970-01-01
    • 2020-03-31
    • 2011-02-27
    相关资源
    最近更新 更多