简体   繁体   中英

How to add another piece of state on ngrx/router-store?

I have a root-level router-store as defined below.

export interface RouterStateUrl {
  url: string;
  queryParams: Params;
  params: Params;
}

export interface State {
  routerReducer: RouterReducerState<RouterStateUrl>;
  // init: fromInit.InitState;
}

export const reducers: ActionReducerMap<State> = {
  routerReducer: routerReducer,
  // initReducer: fromInit.reducer
};

export const getRouterState = createFeatureSelector<
  RouterReducerState<RouterStateUrl> 
>("routerReducer");

I am trying to add an additional piece of state called init that I would like to track along with the router state. How can I create a feature selector that can also access the init state? In other words, how can I create a feature selector that is not type-bound to the RouterReducerState?

Just like you did with your router:

export interface State {
  routerReducer: RouterReducerState<RouterStateUrl>;
  initReducer: fromInit.State;
}

export const reducers: ActionReducerMap<State> = {
  routerReducer: routerReducer,
  initReducer: fromInit.reducer
};

export const getRouterState = createFeatureSelector<
  RouterReducerState<RouterStateUrl> 
>("routerReducer");

export const getInitState = createFeatureSelector<
  fromInit.State 
>("initReducer");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM