![](/img/trans.png)
[英]How to Navigate from a functional component, from a screen in a tab navigator, where that tab navigator is nested in a parent stack navigator
[英]How to reset the stack navigator and then navigate to a Tab in Tab navigator?
onPress={() => {
const resetAction = StackActions.reset({
index: 0,
key: "Tab1",
actions: [navigation.navigate({ routeName: "Tab1" })]
});
navigation.dispatch(resetAction);
}}
我想通过重置堆栈从堆栈导航器的第二个屏幕导航到Tab1。 我没有为此使用Redux。 以当前的方式,我可以重设堆栈或移动到Tab1页面(它被添加为堆栈上的单独屏幕)。 我想先重置堆栈,然后再转到Tab1屏幕。 有什么办法可以做到这一点?
这是我成功的例子
该代码将打开两个屏幕,并根据index
判断要在哪个屏幕前面显示, index
0:显示第一个屏幕, index
1:显示第二个屏幕(此处将显示tab1
屏幕)
希望它对您有所帮助
import { NavigationActions } from 'react-navigation';
const resetAction = NavigationActions.reset({
index: 1,
actions: [
NavigationActions.navigate({ routeName: 'home' }),
NavigationActions.navigate({ routeName: 'Tab1' })
]
})
this.props.navigation.dispatch(resetAction);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.