我要注销后清除商店中的所有状态。 这是我的reducers / index.ts
export interface AppState {
}
export const reducers: ActionReducerMap<AppState> = {
router: routerReducer
};
export const metaReducers: MetaReducer<AppState>[] = !environment.production ? [storeFreeze] : [];
我的app.module.ts
StoreModule.forRoot(reducers, {metaReducers:[]})
在我旁边已经有我的auth reducer(authState),它有两个操作,分别是登录和注销
答案 0 :(得分:0)
我在索引中创建了一个meta-reducer函数,当用户注销时它将清除商店
export function clearState(reducer) {
return function (state, action) {
if (action.type === Auth.AuthActionsTypes.LogoutAction) {
state = undefined;
}
return reducer(state, action);
};
}
,然后将其添加到我的app.module中。
StoreModule.forRoot(reducers, {metaReducers:[clearState]})