这是我的代码
import { NavigationActions } from "react-navigation"
import { call, put, delay } from "redux-saga/effects"
import { AsyncStorage, Alert } from "react-native"
export function* handleResponse(response) {
switch (response.status) {
case 200: {
console.log('logged by phuognn aaa');
Alert.alert("404400404040400")
yield call(NavigationActions.navigate, { routeName: "Auth" })
return true;
}
case 201: {
console.log('logged by phuognn bbb');
return false;
}
}
}
日志行和警报已运行,我想导航到路由“ Auth”,但不起作用。 我的代码有问题吗?
答案 0 :(得分:0)
差错
yield call(NavigationActions.navigate, { routeName: "Auth" })
替换为
this.props.navigation.navigate("Auth");
这里是理解的链接
答案 1 :(得分:0)
NavigationActions.navigate
是动作创建者函数,而不是api调用或类似函数。要从传奇中分派动作,应使用put
而不是call
。
import { NavigationActions } from "react-navigation"
import { call, put, delay } from "redux-saga/effects"
import { AsyncStorage, Alert } from "react-native"
export function* handleResponse(response) {
switch (response.status) {
case 200: {
console.log('logged by phuognn aaa');
Alert.alert("404400404040400");
yield put(NavigationActions.navigate({ routeName: "Auth" }));
return true;
}
case 201: {
console.log('logged by phuognn bbb');
return false;
}
}
}
请尝试使用此代码。我对redux-saga
不太熟悉。我更喜欢redux-observable
,所以请告诉我这是否可行。