[英]Undefined is not an object (evaluating 'this.props.navigator.replace')
I followed a tutorial to use React-Navigation, I got a problem when trying to move to another page. 我遵循了一个使用React-Navigation的教程,尝试移动到另一个页面时遇到了问题。 I get this error:
Undefined is not an object (evaluating 'this.props.navigator.replace')
我收到此错误:
Undefined is not an object (evaluating 'this.props.navigator.replace')
I searched here and on other sites but nothing worked for me. 我在这里和其他网站上进行了搜索,但对我没有任何帮助。 This is the code I have:
这是我的代码:
index: 指数:
import React, { Component } from 'react';
import { Root } from './config/Router';
class Application extends Component{
render(){
return <Root />;
}
}
export default Application;
Router: 路由器:
import React from 'react';
import { StackNavigator } from 'react-navigation';
import Login from '../pages/Login';
import Home from '../pages/Home';
export const Root = StackNavigator({
Login:{
screen: Login,
},
Home:{
screen: Home,
navigatorOptions:{
title: "Homepage"
}
}
});
Login (when clicking the button here, the problem occurs): 登录(单击此处的按钮时,会发生问题):
export default class Login extends Component{
constructor(props){
super(props);
}
_navigate(routeName){
this.props.navigator.replace({
name: routeName
});
}
render(){
return(
<View style = {styles.container}>
<TouchableOpacity onPress={this._navigate.bind(this, 'Home')}>
<Text>
Hello.
</Text>
</TouchableOpacity>
</View>
);
}
}
What am I doing wrong ? 我究竟做错了什么 ?
Thanks in advance. 提前致谢。
According to the React Native docs , you'll want to navigate using this.props.navigation
, not this.props.navigator
: 根据React Native文档 ,您将要使用
this.props.navigation
而不是this.props.navigator
进行导航:
export default class Login extends Component{
constructor(props){
super(props);
}
_navigate(routeName){
this.props.navigation({
name: routeName
});
}
render(){
return(
<View style = {styles.container}>
<TouchableOpacity onPress={this._navigate.bind(this, 'Home')}>
<Text>
Hello.
</Text>
</TouchableOpacity>
</View>
);
}
}
class HomeScreen extends React.Component {
//Some code here
}
class ChatScreen extends React.Component {
//Some code here
}
const SimpleApp = StackNavigator({
Home: { screen: HomeScreen },
Chat: { screen: ChatScreen },
});
AppRegistry.registerComponent('HelloWorld', () => SimpleApp);
You should register "Simple" rather than "HomeScreen" 您应该注册“简单”而不是“ HomeScreen”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.