可以从componentN之外的组件导航componentN(createAppContainer)吗?有可能吗

时间:2019-02-15 00:44:25

标签: react-native react-navigation

我有Component App返回(ComponentMain,ComponentA),其中ComponentMain是createAppContainer。因此,在组件A内部,我想浏览ComponentMain。有可能吗?

1 个答案:

答案 0 :(得分: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);