未定义不是对象'this.props.navigation.navigate'

时间:2019-04-23 17:40:29

标签: javascript reactjs react-native jsx

尝试致电

时出现此错误
 import React, { Component } from 'react';
import { Text, StyleSheet, ScrollView, View, TouchableOpacity, ActivityIndicator , Image} from 'react-native';


export default class Cards extends Component {
  constructor(props) {
    super(props);
  }

  render() {

    return (
      <View style={styles.card}>
        <View style={styles.card_header}>
          <View style={styles.dir}>

            <Image style={styles.account_img} source={require('../../../assets/png/Group_287.png')} />
            <Text style={styles.header_text}>{this.props.name}</Text>
            <View style={{ justifySelf: 'flex-end', flex: 1, marginRight: 20 }}>
            <TouchableOpacity>
              <Image style={[styles.footer_images, { alignSelf: 'flex-end' }]} source={this.props.image} />
            </TouchableOpacity>
            </View>
          </View>
          <Text style={styles.paragraph}>{this.props.text}</Text>
        </View>

        <View style={styles.card_center}>
        <Image style={{width:'100%', height:'100%'}} source={this.props.user_image}/>
        </View>

        <View style={styles.card_footer}>
          <View style={styles.image_container}>
          <TouchableOpacity>
            <Image style={styles.footer_images} source={require('../../../assets/png/like.png')} />
          </TouchableOpacity>
          </View>

          <Text style={{color: '#EEEFF0'}}>{this.props.likes}</Text>

          <View style={styles.image_container}>
          <TouchableOpacity>
            <Image style={styles.footer_images} source={require('../../../assets/png/commenta.png')} />
          </TouchableOpacity>
          </View>

          <Text style={{ color: '#EEEFF0' }}>{this.props.comments}</Text>

          <View style={{ justifySelf: 'flex-end', flex: 1, marginRight: 20 }}>
          <TouchableOpacity onPress={() => this.props.navigation.navigate('Share')}>
            <Image style={[styles.footer_images, { alignSelf: 'flex-end' }]} source={require('../../../assets/png/condividi.png')} />
          </TouchableOpacity>
          </View>
        </View>
      </View>
    );
  }
}

这是我要浏览的课程

import React, { Component } from 'react';
import { Text, StyleSheet, ScrollView, View, TouchableOpacity,Image, ActivityIndicator } from 'react-native';


export default class Share extends Component {
  constructor() {
    super();
    this.state = {
    }
  }

  render() {
    return(
      <View style={{height:20, backgroundColor:'red'}}></View>
    )
}


}

路线:

  Share: {
      screen: Share,
      navigationOptions: {
        headerLeft: HeaderLeft,
        headerRight: HeaderRight,
        headerStyle: {
          elevation: 0,
          shadowOpacity: 0,
          borderBottomWidth: 0,
        }
      }
    },

我要放置的类是在另一个组件中导出的类,以便能够创建相同类型的组件。 如果我在没有导出到任何地方的另一个类中使用导航功能,就可以了。为什么会发生这种情况,请帮助我解决问题?

0 个答案:

没有答案