如何解决注销后如何清理ngrx存储
我要注销后清除商店中的所有状态。 这是我的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),它有两个操作,分别是登录和注销
解决方法
我在索引中创建了一个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]})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。