我正在尝试导航到主屏幕,如果 JS DEBUGGER 为 ON(正在运行),代码仍然可以正常工作,但问题是当我尝试在 JS DEBUGGER 为 OFF(禁用)时运行我的应用程序并尝试在那时登录“yield put(NavigationActions.navigate({ routeName: 'Main' }));" 这段代码没有重定向到主屏幕。
下面是我的代码:
import { NavigationActions } from 'react-navigation';
import { call, put, takeEvery, take } from 'redux-saga/effects';
import { getFirebase } from 'react-redux-firebase';
export function* watchLoginAsync({email, password}) {
try {
const response = yield getFirebase().login({email,password});
if (response.uid) {
// dispatchToMain();
yield put(NavigationActions.navigate({ routeName: 'Main' }));
// yield put({type: LOGIN_SUCCESS });
} else {
yield put({type: LOGIN_FAIL, error: 'Something went wrong seriously!!'});
}
} catch(err => console.log(err))
}
export default function* watchLogin() {
yield takeEvery(LOGIN_REQUESTING, watchLoginAsync);
}
这是 store.js 文件(我将 redux-saga 与 react-redux-firebase 集成在一起)
const sagaMiddleware = createSagaMiddleware();
const middleware = [ sagaMiddleware ];
const firebaseConfig = {
apiKey: '******',
authDomain: '****',
databaseURL: '****',
projectId: '****',
storageBucket: '****',
messagingSenderId: '****',
};
const reduxFirebaseConfig = {
userProfile: 'users',
enableLogging: true,
enableRedirectHandling: false,
};
// Add redux Firebase to compose
const createStoreWithFirebase = compose(
reactReduxFirebase(fbConfig, reduxFirebaseConfig),
applyMiddleware(...middleware)
)(createStore);
// Add Firebase to reducers
const rootReducer = combineReducers({
firebase: firebaseStateReducer,
......
});
// Create store with reducers and initial state
const initialState = {}
export default createStoreWithFirebase(rootReducer, initialState);
// when calling saga, pass getFirebase
sagaMiddleware.run(Sagas, getFirebase)
注意:如果在应用程序运行时 JS DEBUGGER 在 iOS 模拟器上,代码完全可以正常工作。