【问题标题】:undefined is not an object (evaluating '_this.props.navigator.push') react native , when i am trying to navigate from one page to another当我试图从一个页面导航到另一个页面时,未定义不是一个对象(评估'_this.props.navigator.push')反应原生
【发布时间】:2017-07-07 10:41:47
【问题描述】:

这里是示例代码,我正在尝试 react-native-navigation

我使用 react-native init navigate 来启动项目 然后我安装了

纱线添加 react-native-navigation@latest

代码在第一个屏幕上运行完美,但是当我调用 showNextScreen 函数时它会抛出错误

undefined is not an object (evaluate 'this.props.navigator.push') react native

  import React, { Component } from 'react';
    import {
      AppRegistry,
      StyleSheet,
      Text,
      View
    } from 'react-native';
    import {Navigation} from 'react-native-navigation';
    import firstPage  from './app/components/firstPage';
    export default class navigate extends Component {
    //function to move to next screen
      showNextScreen = () =>{
        this.props.navigator.push({
          screen: 'firstPage',
          title: 'firstScreen'
        })
      }
      render() {
        return (
          <View style={styles.container}>
            <Text style={styles.welcome}>
              Welcome to React Native!
            </Text>
            <Text style={styles.instructions}>
              To get started, edit index.android.js
            </Text>
            <Text onPress={this.showNextScreen.bind(this)} 
            style={styles.instructions}>
              Double tap R on your keyboard to reload,{'\n'}
              Shake or press menu button for dev menu
            </Text>
          </View>
        );
      }
    }

    const styles = StyleSheet.create({
      container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF',
      },
      welcome: {
        fontSize: 20,
        textAlign: 'center',
        margin: 10,
      },
      instructions: {
        textAlign: 'center',
        color: '#333333',
        marginBottom: 5,
      },
    });

    AppRegistry.registerComponent('navigate', () => navigate);

【问题讨论】:

    标签: javascript android react-native


    【解决方案1】:

    使用 React Native Navigation,您必须以不同于最初的方式引导您的应用程序。原生导航不使用 registerComponent 设置,因为它是原生导航器。

    他们的文档https://wix.github.io/react-native-navigation/#/usage中列出了完全设置的步骤

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多