关于angular:通过ngrx 8 createReducer()和on()函数使用@ ngrx / router-store操作

Using @ngrx/router-store actions with ngrx 8 createReducer() and on() function

我有一个ngrx v8样式缩减器(在createReducer上使用),需要对路由更改做出反应。

1
2
3
4
5
6
7
let myAcction = createAction('my action', prop<boolean>);

let reducer = createReducer(
  initialState,
  on(myAction, (state, prop) => ({...state, example=prop })),
  on(ROUTER_NAVIGATION, (state, routeParams) => ({...state, example2:{...routeParams}}))
)

由于ROUTER_NAVIGATION不是动作创建者,因此无法编译:

Argument of type '"@ngrx/router-store/navigation"' is not assignable
to parameter of type 'ActionCreator>'.
Type '"@ngrx/router-store/navigation"' is not assignable to type 'FunctionWithParametersType'

它也不能与RouterNavigationAction一起使用:

Argument of type 'boolean' is not assignable to parameter of type
'ActionCreator>'

如何在createReducer / on函数中使用ngrx / router-store操作?我找不到为给定动作导出的动作创建者。


我会在其存储库上针对ngrx提出问题。同时,您可以在对象:{ type: ROUTER_NAVIGATION }中使用令牌来破解它,因为这是其在内部的工作方式。这不是理想的方法,但是在他们修复它之前它才起作用。