[英]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.