我在@ngrx/router-store
中使用了一个定制的序列化程序
export interface CustomSerializer {
url: string;
params: Params;
queryParams: Params;
data: Data;
showFilter: boolean;
}
我已经完成了基本设置,商店正在使用串行器类型跟踪我的路由,这与预期不谋而合。
我希望能够访问由内置操作触发的自定义类型,如下所示
test$ = createEffect(() =>
this.actions$.pipe(
ofType(routerNavigatedAction),
tap(({ payload }) => {
console.log('filter?:' + payload.routerState.showFilter); <-- not allowed by typescript
})
), { dispatch: false }
);
但是routerNavigatedAction
提供的payload
是RouterNavigatedPayload<SerializedRouterStateSnapshot>
类型的。SerializedRouterStateSnapshot
只知道root
和url
,对showFilter
一无所知,即使它在运行时就在那里
(在点击前调试断点()):
有没有办法让我绑定到核心路由事件,并配置基础设施来返回我的自定义序列化程序类型?如果没有,有没有一个“好”的方法来获得我的效果中的showFilter属性?我知道我可以使用选择器从存储中获取强类型的数据,但我更喜欢使用effect已经提供的有效负载。
发布于 2020-11-07 08:57:00
我想这就是你要找的
test$ = createEffect(() =>
this.actions$.pipe(
ofType<RouterNavigatedAction<CustomSerializer>>(routerNavigatedAction),
tap(({ payload }) => {
console.log('filter?:' + payload.routerState.showFilter);
})
), { dispatch: false }
);
https://stackoverflow.com/questions/64723830
复制