Jus*_*wan 2 javascript reactjs react-native react-navigation
我在 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}
}
});
Run Code Online (Sandbox Code Playgroud)
我现在在PinEntry屏幕中,我想返回到TabNavigator 中的Transactions选项卡。我可以使用以下脚本返回主页选项卡:
const resetAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate('Home')]
});
this.props.navigation.dispatch(resetAction);
Run Code Online (Sandbox Code Playgroud)
但我的目标是回到特定的标签位置,在这种情况下是“交易”标签。
我已经用谷歌搜索了很多次,但没有解决方案,任何帮助将不胜感激。
我找到了解决方案:
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3076 次 |
| 最近记录: |