react-native - 导航堆栈为空时如何导航到特定屏幕?
问题描述
我怎样才能做到这一点:
if navigation stack is not empty
this.props.navigation.goBack()
else
this.props.navigation.navigate('CustomScreen')
解决方案
解决方法是从前一个屏幕发送参数,并在当前屏幕检查该参数是否存在
屏幕1:
this.props.navigation.navigate('Screen2', {prevScreen: 'Screen1'});
屏幕2:
if(this.props.navigation.getParam('prevScreen', null))
this.props.navigation.goBack();
else
this.props.navigation.navigate('CustomScreen');
推荐阅读
- python - 如何覆盖石墨烯中的 DjangoModelFormMutation 字段类型?
- android-studio - Android emulator - dummy emulator-5554 和 AVD ... 已经在运行
- php - 登录后如何根据他的类型将用户重定向到不同的路由
- c# - 如果行以“ *:”开头,C#如何选择任何字符
- javascript - 中止之前正在运行的异步 componentDidMount
- java - JSP中HashMap中的重复键
- git - 我怎样才能拉/制作
当我用 --depth=1 克隆树时,进入头部? - xargs - fswatch 未运行脚本,报告为未找到
- html - 分隔网页页脚中的超链接
- velocity - 用于计算移动窗口中价格速度的 Esper EPL 查询