反应导航-导入文件导航页面

时间:2020-01-23 22:50:03

标签: react-native react-navigation expo react-navigation-drawer

此文件导入

class Footer extends Component {
  _notifications = () => {
    const { navigate } = this.props.navigation;
    navigate('Ntf', {});
  }

  render() {
    return (<TouchableHighlight onPress={() => this._notifications()} ></TouchableHighlight>);
  }
}

此文件主要(React-Navigation-NavigationDrawerStructure)。

import { Footer } from './Footer';
export default class HomePage extends Component {
render() {
    return (<View><Footer/></View>);
}

错误后单击_notifications按钮:undefined是一个对象c.props.navigation.navigate 请帮助我

1 个答案:

答案 0 :(得分:0)

只有在路线中定义的组件才能访问导航道具,而不能访问这些组件的子项!。

解决方案:-

导入文件

IAsset

主文件:-

class Footer extends Component {
  _notifications = () => {
     this.props.NavigateToNTF()
  }

  render() {
    return (<TouchableHighlight onPress={() => this._notifications()} ></TouchableHighlight>);
  }
}

子级组件中没有导航道具,这就是为什么您在调用导航道具时无法定义导航的原因,但是通过这种解决方案,我们将道具从父文件(主文件)发送到子项(导出文件),因此它将工作!

如果有帮助!确保激励我-你知道我的意思!