可以从组件外部组件导航组件(createAppContainer)吗?有可能吗?

问题描述 投票:0回答:1

我有Component App返回(ComponentMain,ComponentA),ComponentMain是一个createAppContainer。因此,在组件A中我想要导航ComponentMain。这是可能的?

react-native react-navigation
1个回答
0
投票

您可以将withNavigation用于外部stackNavigator组件,以使用navigation作为道具。

以下是如何使用withNavigation的示例:

import React from 'react';
import { Button } from 'react-native';
import { withNavigation } from 'react-navigation';

class ComponentA extends React.Component {
  render() {
    return <Button title="Back" onPress={() => { this.props.navigation.goBack() }} />;
  }
}

// withNavigation returns a component that wraps MyBackButton and passes in the
// navigation prop
export default withNavigation(ComponentA);
© www.soinside.com 2019 - 2024. All rights reserved.