gpt4 book ai didi

javascript - react 导航 : How to go back to root Tab Navigator with specific tab from child stack

转载 作者:行者123 更新时间:2023-11-30 08:22:51 25 4
gpt4 key购买 nike

我在 React Native 中使用 react-navigation v2,每当想返回到根导航器中的特定 选项卡时就会卡住。

我有以下路线堆栈:

const HomeStack = createStackNavigator(
{
Home: Home,
CreateInvoice: CreateInvoiceScreen,
InvoiceSummary: InvoiceSummaryScreen,
PinEntry: PinEntryScreen
},
{
navigationOptions: {
header: null
}
}
);

const CustomersStack = createStackNavigator(
{
Customers: CustomersScreen,
Details: CustomerDetailsScreen
},
{
navigationOptions: {
header: null
}
}
);

const Tab = createBottomTabNavigator(
{
Home: HomeStack,
Transactions: TransactionsTab,
Customers: CustomersStack,
Settings: SettingsTab
}
);

const Routers = createStackNavigator({
splash: {
screen: SplashScreen,
navigationOptions: {...navigationOptions}
},
login: {
screen: LoginScreen,
navigationOptions: {...navigationOptions}
},
home: {
screen: HomeScreen,
navigationOptions: {...navigationOptions}
}
});

我现在在 PinEntry 屏幕,我想返回到 TabNavigator 中的 Transactions 标签。我可以使用以下脚本返回主页标签:

const resetAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate('Home')]
});
this.props.navigation.dispatch(resetAction);

但我的目标是返回到特定的标签位置,在本例中是“交易”标签。

我已经用谷歌搜索了很多次,但没有解决方案,我们将不胜感激。

最佳答案

我找到了解决方案:

const resetAction = StackActions.reset({
index: 0,
key: null,
actions: [NavigationActions.navigate({ routeName: 'Home' })]
});
const goToTransaction = NavigationActions.navigate({
routeName: 'Transactions'
});
this.props.navigation.dispatch(resetAction);
this.props.navigation.dispatch(goToTransaction);

关于javascript - react 导航 : How to go back to root Tab Navigator with specific tab from child stack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50774395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com