我有一个在react中开发的应用程序。 我的问题是当我在两个选项卡中打开应用程序时。从那个选项卡,我将在那个时候注销我的减速器设置访问令牌null,这是预期的,但是当我从那里选择选项卡2时,我将导航到我的商店自动恢复的另一页,以便用户可以访问我的应用程序即使注销也是如此。
我的调度功能
const mapDispatchToProps = dispatch => {
return {
logout: token => dispatch({ type: actionTypes.LOGOUT_USER, value:
null }),
};
};
我的减速器功能
const userReducer = (state = initialState, action) => {
switch (action.type) {
case actionType.LOGIN_USER:
return {
...state,
user: action.value,
};
case actionType.LOGOUT_USER:
return {
state: null,
};
default:
return state;
}
}
我的redux配置:
const persistConfig = {
key: 'root',
storage: storage,
stateReconciler: autoMergeLevel2,
};
const pReducer = persistReducer(persistConfig, userReducer);
const store = createStore(pReducer, applyMiddleware(thunk));
const persistor = persistStore(store);
persist:root应该为空。