Javascript 如何使用redux saga使用react导航

Javascript 如何使用redux saga使用react导航,javascript,react-native,navigation,redux-saga,Javascript,React Native,Navigation,Redux Saga,我有一个登录屏幕来登录,如果状态为200,我需要将用户导航到另一个屏幕。我用redux传奇来处理副作用。如果响应状态为200,如何将用户导航到其他用户 LoginSaga.js import {call, put} from 'redux-saga/effects'; import {Alert} from 'react-native'; import LoginActions from '../../Login/LoginActions'; import {navigate} from '..

我有一个登录屏幕来登录,如果状态为200,我需要将用户导航到另一个屏幕。我用redux传奇来处理副作用。如果响应状态为200,如何将用户导航到其他用户

LoginSaga.js

import {call, put} from 'redux-saga/effects';
import {Alert} from 'react-native';
import LoginActions from '../../Login/LoginActions';
import {navigate} from '../../../Service/NavigationService';
import {getAuth} from '../../../Service/LoginService';

export function* fetchAuthSaga(authInfo) {
  try {
    const response = yield call(getAuth, authInfo);
    if (response.status === 200) {
      navigate('Registration');
      yield put(LoginActions.fetchAuthSuccess(response.data));
    }
  } catch (err) {
    yield put(LoginActions.fetchAuthFailure(err));
    return Alert.alert('Username or Password incorrect');
  }
}

import * as React from 'react';

export const navigationRef = React.createRef();

export function goBack() {
  navigationRef.current?.goBack();
}
export function navigate(name, params) {
  navigationRef.current?.navigate(name, params);
}

NavigationService.js

import {call, put} from 'redux-saga/effects';
import {Alert} from 'react-native';
import LoginActions from '../../Login/LoginActions';
import {navigate} from '../../../Service/NavigationService';
import {getAuth} from '../../../Service/LoginService';

export function* fetchAuthSaga(authInfo) {
  try {
    const response = yield call(getAuth, authInfo);
    if (response.status === 200) {
      navigate('Registration');
      yield put(LoginActions.fetchAuthSuccess(response.data));
    }
  } catch (err) {
    yield put(LoginActions.fetchAuthFailure(err));
    return Alert.alert('Username or Password incorrect');
  }
}

import * as React from 'react';

export const navigationRef = React.createRef();

export function goBack() {
  navigationRef.current?.goBack();
}
export function navigate(name, params) {
  navigationRef.current?.navigate(name, params);
}

导航功能显示未定义。如何解决这个问题


谢谢,提前

你确定你完成了报告中提到的所有事情吗?再次检查,可能您遗漏了一些内容,因为
导航
不应该是
未定义的
。也请注意教程的部分。谢谢,我错过了导航容器中的参考。现在它工作得很好