扩展@ ngrx / router-store routerReducer以修改添加到RouterStateUrl的字段

问题描述 投票:0回答:1

如何扩展逻辑对于Angular 8,我使用自定义序列化程序保持ngrx 8的路由器状态

export class CustomSerializer implements RouterStateSerializer<RouterStateUrl>凡自定义状态

export interface RouterStateUrl {
url: string;
path?: string[];
params: Params;
queryParams: Params;
breadcrumbs: Breadcrumb[];

}添加一个新字段-breadcrumbs

对于整个商店,我都有一个简化图,如下所示:

export interface State {
  router: fromRouter.RouterReducerState<any>;
  //... other feature states
}

export const reducers: ActionReducerMap<State> = {
router: fromRouter.routerReducer,
 // ...other feature reducers
};

我想操纵路由器状态的自定义部分(面包屑字段)。是否有一种标准的方式来扩展routerReducer,以允许更改自定义字段?

更新:我看到的一种可能的解决方法是在商店中为面包屑创建一个单独的功能,同时保持路由器状态功能的纯净。这将需要新功能来减少路由器操作。在我看来,这是一个hack。路由器状态允许使用额外的字段来扩展状态,而不是简化器,这似乎是不合逻辑的]

angular ngrx ngrx-store ngrx-router-store ngrx-store-8.0
1个回答
0
投票

目前尚无法将自定义操作添加到内置路由器减速器中。

根据您的需要,您可以:

  • 如上所述,根据路由器的动作创建自己的reduceer
  • 根据路由器状态创建选择器以建立面包屑
© www.soinside.com 2019 - 2024. All rights reserved.