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

322 Views Asked by At

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?

1

There are 1 best solutions below

0
On

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");