无法在React navigation 4中读取undefined的属性'navigate'

时间:2018-05-05 09:46:12

标签: react-native react-navigation

我有这个屏幕NewsTabScreen.js

class NewsTabScreen extends Component {
render() {
const { navigate } = this.props.navigation;
return (
  <Container style={style.container}>
    <Tabs renderTabBar={() => <ScrollableTab tabsContainerStyle={{backgroundColor: Platform.OS == 'ios' ? '#F8F8F8' : '#3F51B5'}}/>}>
    <Tab heading={
      <TabHeading>
        <Text style={{ fontSize: 14 }}>{I18n.t("news")}</Text>
      </TabHeading>}>
      <News/>
    </Tab>
    <Tab heading={
      <TabHeading>
        <Text style={{ fontSize: 14 }}>{I18n.t("newsOfCommittees")}</Text>
      </TabHeading>}>
      <ComNews/>
    </Tab>
    <Tab heading={
      <TabHeading>
        <Text style={{ fontSize: 14 }}>{I18n.t("requests")}</Text>
      </TabHeading>}>
    <RequestsNews/>
    </Tab>
    </Tabs>
  </Container>
);}}

当我点击新闻上的项目时,我收到错误

  

无法读取undefined

的属性'navigate'

1 个答案:

答案 0 :(得分:0)

如果News组件不属于任何导航器,但您仍想访问withNavigation,则需要将navigation组件与class News extends React.Component { ... } export default withNavigation(News); 一起打包,请查看文档here < / p>

<form method="POST" action="{{url('submit', [$id])}}">
    {{ csrf_field() }}
    <button type="submit">Submit</button>
</form>

希望这会有所帮助!