NullInjectorError: No provider for RouterStateSerializer

NullInjectorError: No provider for RouterStateSerializer

我已经将一个小的副项目从 angular 6 升级到 8,但我现在收到一个我不明白的错误。

  StaticInjectorError(Platform: core)[StoreRouterConnectingModule -> RouterStateSerializer]: 
    NullInjectorError: No provider for RouterStateSerializer!
    at NullInjector.get (http://localhost:4200/vendor.js:36416:27)
    at resolveToken (http://localhost:4200/vendor.js:36743:24)
    at tryResolveToken (http://localhost:4200/vendor.js:36669:16)
    at StaticInjector.get (http://localhost:4200/vendor.js:36532:20)
    at resolveToken (http://localhost:4200/vendor.js:36743:24)
    at tryResolveToken (http://localhost:4200/vendor.js:36669:16)
    at StaticInjector.get (http://localhost:4200/vendor.js:36532:20)
    at resolveNgModuleDep (http://localhost:4200/vendor.js:58166:29)
    at _createClass (http://localhost:4200/vendor.js:58243:32)
    at _createProviderInstance (http://localhost:4200/vendor.js:58199:26)

谁能看看并给我一些指点。可以找到代码 here。提前致谢!

我设法让它工作 - 很难,请注意其他解释问题性质的答案,而不仅仅是简单的“愚蠢”修复。

打开文件 cards.module.ts 并移除 StoreRouterConnectingModule 的导入 它是冗余的..它构建和运行完美。

不客气:)

从 6 到 8,StoreouterConnectingModule 的 imports 语句略有变化,您需要调用 forRoot() 方法,如 ngrx 文档 here

代码示例:

import { StoreRouterConnectingModule, routerReducer } from '@ngrx/router-store';
import { AppComponent } from './app.component';

@NgModule({
  imports: [
    BrowserModule,
    StoreModule.forRoot({
      router: routerReducer,
    }),
    RouterModule.forRoot([
      // routes
    ]),
    // Connects RouterModule with StoreModule
    StoreRouterConnectingModule.forRoot(),
  ],
  bootstrap: [AppComponent],
})
export class AppModule {}