我按照教程使用React-Navigation,当尝试移动到另一个页面时出现问题。我得到这个错误:Undefined is not an object (evaluating 'this.props.navigator.replace')
未定义不是对象(评估'this.props.navigator.replace')
我在这里和其他网站搜索,但没有为我工作。 这是我的代码:
指数:
import React, { Component } from 'react';
import { Root } from './config/Router';
class Application extends Component{
render(){
return <Root />;
}
}
export default Application;
路由器:
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"
}
}
});
登录(这里点击该按钮时,出现问题):
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>
);
}
}
我究竟做错了什么 ?
在此先感谢。
是'this.props'未定义? –
我该如何检查?对于愚蠢的问题感到抱歉,我一般都会对本机和网络做出反应。 –
您可以通过在渲染方法的第一行运行'console.log(this.props)'来检查,然后检查浏览器日志中的跟踪 这可能有助于查看您正在使用哪个教程) –