首页 > 解决方案 > 未定义不是对象(评估 this.props.route.params.text)

问题描述

我按照 React Navigation Doc 将参数传递到我的上一个屏幕,但是当我在上一个屏幕中访问它时出现错误说

评估 this.props.route.params.text

export default class SelectMap extends Component{
    constructor() {
        super()
      }
    render(){
        const {text} = this.props.route.params
        return (
            <View style={{alignItems: 'center', justifyContent:'center'}}>
                <TouchableOpacity onPress={() => this.props.navigation.navigate('MapView')}>
                    <Text>
                        Open Maps
                    </Text>
                    <Text>
                        {text}
                    </Text>
                    
                </TouchableOpacity>       
            </View>
        )
    }
}

这就是我发送参数的方式

this.props.navigation.navigate('SelectMap', {text:JSON.stringify(this.state.marker)})

标签: react-nativereact-navigation

解决方案


您的构造函数必须如下

constructor(props) {
  super(props);
}

推荐阅读