reactjs - 在“Redux-Saga”中使用“React Navigation 6.0”重定向用户
问题描述
我正在使用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',
}),
),
);
但两者都没有效果。
解决方案
更改并routeName
尝试name
yield put(NavigationActions.navigate({name: 'ProfilePageScreen'}));
如果您要从 切换React Navigation 4
到React Navigagtion 6
现在转移到另一个调用的包NavigationActions
,从那里你可以打电话,从那里你可以导航。deprecated
@react-navigation/native
commonActions
推荐阅读
- android - 颤振 - 原生广告不会加载和显示,而且它的事件回调也没有显示任何内容
- android - android api 29 上的 adb remount 是否损坏?
- python - 未正确生成以字母“s”结尾的 ORM 类
- python - 根据文本方向检测图像方向角度
- typo3 - 如何在 Typo3 extbase 后端扩展中将 csv 文件导入数据库
- xslt - XML/XSL 帮助
- android - 避免重复的广义函数
- python-3.x - 如何使用类将文本绘制到窗口?
- c# - 在处理请求中连接到 SQL Server 失败
- javascript - 使用谷歌云功能部署 api