React native undefined不是对象(评估';this.props.\u导航.替换/推送';)

React native undefined不是对象(评估';this.props.\u导航.替换/推送';),react-native,React Native,我对React Native很陌生,并且尝试(按照教程)在单击按钮时移动到另一个屏幕,这是我的更新代码和按下按钮时出现的错误的照片。 index.ios.js: export default class Application extends Component { constructor(){ super(); } renderScene(route, navigator){ if(route.name == 'login'){ return <

我对React Native很陌生,并且尝试(按照教程)在单击按钮时移动到另一个屏幕,这是我的更新代码和按下按钮时出现的错误的照片。 index.ios.js:

export default class Application extends Component {

  constructor(){
    super();
  }

  renderScene(route, navigator){
    if(route.name == 'login'){
      return <Login navigator={navigator}/>
    }else if(route.name == 'home'){
      return <Home navigator={navigator}/>
    }
  }

  render() {
    return <Navigator
      initialRoute={{name: 'login'}}
      renderScene={this.renderScene.bind(this)}/>
  }
}
导出默认类应用程序扩展组件{
构造函数(){
超级();
}
renderScene(路线、导航器){
如果(route.name==“login”){
返回
}else if(route.name==“home”){
返回
}
}
render(){
返回
}
}
登录信息:

export default class LoginForm extends Component{
    constructor(props){
        super(props);
        this.navigate = this.navigate.bind(this);
    }

    navigate(routeName){
        this.props.navigator.replace({
            name: routeName,
            Component: Home
        });
    }
    render(){ 
        return(
            <View style={mStyle.container}>
                <StatusBar barStyle='light-content'/>
                <TouchableOpacity>
                    <Text style={mStyle.btnText}>
                        LOGIN WITH FACEBOOK
                    </Text>
                </TouchableOpacity>
                <TouchableOpacity onPress={()=>this.navigate('home')}>
                    <Text style={mStyle.noLoginTxt}>
                        CONTINUE WITHOUT LOGIN
                    </Text>
                </TouchableOpacity>
            </View>
        );
    }
}
导出默认类LoginForm扩展组件{
建造师(道具){
超级(道具);
this.navigate=this.navigate.bind(this);
}
导航(路由名称){
this.props.navigator.replace({
名称:routeName,
组成部分:家庭
});
}
render(){
返回(
使用FACEBOOK登录
这个。导航('home')}>
不登录继续
);
}
}
当点击按钮时,我试图从登录屏幕移动到主屏幕。 按下仿真器上的按钮时出现此问题:
您面临的几个问题

1.-语法为:

this.props.navigator.{any_method}
例如:

  • this.props.navigator.push
  • this.props.navigator.replace
不是

2.-如果您有子视图,请确保您正在向子视图发送
Navigator
属性,例如

<View>
  <MyChildComponent navigator={this.props.navigator} />
</View>


这是因为在
Navigator
中使用的属性与组件中使用的属性不匹配

改变

constructor(){
    super();
    this._navigate = this._navigate.bind(this);
}
_navigate(name){
        this.props._navigate.replace({ //I also tried push, same problem.
            name
        });
 }


你能给我们提供一个如何使用
导航器的示例吗?我刚从React Native开始,所以我做了他在这里做的事情:我尝试了你的建议,但仍然遇到了同样的问题。你能通过添加视图来编辑你的问题吗?该视图呈现了你对问题的看法,以便我们可以更详细地看到问题。谢谢,完成了。我从这段视频中了解到:我刚开始学习React Native。我对我的答案做了更新。如果你有问题或仍然有问题,请告诉我。谢谢,但我仍然遇到同样的问题。这太奇怪了,在教程中看起来很简单。我累了,现在是这样,但还是一样的问题。你能用上面的代码发布错误吗。除非您在navigator中做了一些不同的操作,否则这应该是可行的。另外,请确保您执行的是props.navigator而不是props.navigate。我使用现在更新的代码和在模拟器中获得的错误照片编辑了OP。谢谢:)。真奇怪,这不管用。在调用replace方法之前,可以添加console.log(this.props)和console.log(this.props.navigator)。
constructor( props ){
    super( props );
    // The following line is not required since you are using an arrow function to call this one. 
    // this._navigate = this._navigate.bind(this);
}
_navigate(name){
        this.props._navigate.replace({ //I also tried push, same problem.
            name
        });
 }
_navigate(name){
        this.props.navigator.replace({ //I also tried push, same problem.
            name
        });
}