【发布时间】:2021-11-06 11:02:54
【问题描述】:
我正在使用React Navigation 6.0,我想在调用特定函数后推送或重定向用户。
在我的redux saga 函数中:
export function* Login({payload}) {
try {
const response = yield call(loginUser, payload);
yield call(setToken(response.token));
yield put(NavigationActions.navigate({routeName: 'ProfilePageScreen'}));
} catch (error) {
console.log(error)
}
注意我用过:
yield put(NavigationActions.navigate({routeName: 'ProfilePageScreen'}));
使用AsyncStorage 保存令牌后尝试重定向用户。
但是,这不起作用。令牌保存在redux saga 中后,如何重定向我的用户?请帮忙!
更新:我根据React Navigation 6 尝试了以下两种方法。
yield call(
navigation.dispatch(
CommonActions.navigate({
name: 'ProfileScreen',
}),
),
);
还有:
yield put(
navigation.dispatch(
CommonActions.navigate({
name: 'ProfileScreen',
}),
),
);
但两者都没有效果。
【问题讨论】:
标签: reactjs react-native react-navigation