javascript - 如何解决无法读取react-native上未定义的属性 'push'?

标签 javascript reactjs react-native

我正在使用 RN 0.46.0,在设置登录组件后,我尝试使用导航器推送另一个组件。但显示了这个

Cannot read property 'push' of undefined

当我点击按钮时

即使文档也只有这种方式来获取另一个组件。

有人知道这是否与版本有关?

或者导航需要创建一条路线?

import React, {Component} from 'react';
import { Text,  View, Navigator, TouchableHighlight } from 'react-native';
import { Card, CardSection, Input, Button } from './common';
import Signup from './Signup';

class Login extends Component {



     goToSignup(){
    this.props.navigator.push({
      component: Signup
    });
  }




    render() {


        return(

            <Card>            

            <CardSection>

            </CardSection>

            <CardSection>
            <Input

            placeholder="Email"
            />

            </CardSection>

            <CardSection>
            <Input
            secureTextEntry

            placeholder="Password"
            />


            </CardSection>

            <CardSection>

            <Button>
            Log In
            </Button>        
            </CardSection>   
            <CardSection>

   <TouchableHighlight onPress={this.goToSignup.bind(this)}>

<Text >
    Go to Sign up
      </Text>       


    </TouchableHighlight>


</CardSection>


</Card>





);

}


}



export default Login;

最佳答案

React-Native v0.46 没有 Navigator 组件。自 v0.44 起它已被删除。您必须使用其他导航解决方案。

React-Navigation (推荐,由 React 社区创建)

其他第三方解决方案:

React Native Navigation

Native Navigation

关于javascript - 如何解决无法读取react-native上未定义的属性 'push'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46985564/

相关文章:

javascript - 将 class= 属性添加到已定义的 <svg>

react-native - React Native - 如何在字体缩放后检测字体大小?

javascript - 将鼠标事件从 iframe 传播到托管文档

javascript - 如何将 mysql 数据通过管道传输到浏览器窗口而不是 Nodejs 中的控制台?

javascript - 忽略 JSHint 中的全局变量

javascript - javascript代码首先使用setTimeout可以工作,但随后崩溃还是不起作用?

javascript - 如何在循环中生成react html

javascript - 如何处理 react 中的进口 hell ?

ios - 未知的执行上下文错误 - 将 Realm 导入 Expo React Native IOS 应用程序

javascript - 在 react native 应用程序中保留 Firebase 数据