javascript - undefined 不是对象(评估 '_this.props.navigator.push' )

标签 javascript react-native

我正在尝试从主屏幕导航到另一个屏幕(测试)。下面有“HomeScreen.js”。单击注册按钮后,出现上述错误。

我已经处理了整整一天,但似乎无法得到直接的答案。

错误出在我的“Homescreen.js”上(附上屏幕截图错误) Screenshot

错误指向:_handleRegisterView 函数下的 this.props.navigator.push

HomeScreen.js

import React from 'react';
import {
  StyleSheet,
  Text,
  View,
  AsyncStorage,
  Component,
  TouchableHighlight,
  AppRegistry
} from 'react-native';

import Test from './Test';

import { StackNavigator } from 'react-navigation';

class HomeScreen extends React.Component {
  static navigationOptions = {
    title: 'SpeedHack',
  };

  _handleRegisterView = () => {

    this.props.navigator.push({
      title: 'Test',
      component: Test,
      backButtonTitle: 'Back'
    })
    //alert('Register button Pressed!.');
  }

render() {
    return (

      <View style={styles.container}>
        <TouchableHighlight onPress={this._handleRegisterView}>
          <Text style={[styles.button, styles.blueButton]}>
            Register
          </Text></View>
    );
  }
}

Test.js(没有真正做任何有趣的事情,加载图像)

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

class Test extends React.Component {
  render() {
    let pic = {
      uri: 'https://upload.wikimedia.org/wikipedia/commons/d/de/Bananavarieties.jpg'
    };
    return (
      <View style={styles.container}>
        <Text>Ssup Dude! Want some bananas?</Text>
        <Image source = {pic} style = {{width: 300, height: 300}}/>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

最佳答案

你似乎很困惑。在 react-navigation 中,为了推送屏幕,您不执行 this.props.navigator.push,而是使用 this.props.navigation.navigate.

关于javascript - undefined 不是对象(评估 '_this.props.navigator.push' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48349211/

相关文章:

javascript - readline rl.write 如何工作?

javascript - 如何告诉用户使用浏览器检测在 Chrome 中打开页面

javascript - 在选中多个复选框之前禁用提交按钮

javascript - 如何移动/重新排序 html 表格行

firebase - [Firebase错误: Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app).]

android - 如何从一个项目构建多个具有不同应用程序名称、图标、设置、

react-native - ListView 未显示在 react native 中

react-native - 在 React Navigation 5 中的另一个导航器中导航到屏幕

android - 如果应用程序关闭则推送通知(React-Native)

javascript - 如何限制动态创建的选择框中的重复值?