我正在使用 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 社区创建)
其他第三方解决方案:
关于javascript - 如何解决无法读取react-native上未定义的属性 'push'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46985564/