简体   繁体   English

React-Native Navigator“未定义不是对象(正在评估this.props.navigator)”错误

[英]React-Native Navigator “Undefined is not an object (evaluating this.props.navigator)” error

I am very very knew to React Native (and Stackoverflow) and I have been working on switching screens using the Navigator and I still have not been able to do so after researching for help for two days, so I finally resorted to posting a question. 我对React Native(和Stackoverflow)非常了解,我一直在使用Navigator来切换屏幕,但是在研究了两天的帮助后,我仍然无法这样做,因此我终于提出了一个问题。 My code gives me an : "Undefined is not an object (evaluating this.props.navigator)" error and this is the code that I have: 我的代码给了我一个错误:“未定义不是对象(正在评估this.props.navigator)”错误,这是我拥有的代码:

A Navigator class: Navigator类:

import HomeScreen from './HomeScreen';

import LoginScreen from './LoginScreen'

export default class Navigation extends Component {
    render() {

    return (

       <Navigator

       initialRoute={{id:"Login"}}

        renderScene={(route, navigator) =>
        {return this.renderScene(route, navigator)}}
      />
    );
}

renderScene(route, navigator) {

    switch(route.id) {

        case "Login":

            return (<LoginScreen {...route.passProps} navigator={navigator}/>);

        case "Home": 

            return (<HomeScreen {...route.passProps} navigator={navigator}/>);

    }
}
} 

and a LoginButton component in a LoginScreen.js file 和LoginScreen.js文件中的LoginButton组件

class LoginButton extends Component {

    render() {
       const routes = [{id:'LoginScreen'},{id:'HomeScreen'}];
        return (

           <View style={{height:50}}>
            <Container>
                <Content>
                    <Button style={{backgroundColor: '#eeb211'}} onPress={this.nextScreen.bind(this)} rounded >              Login Next Screen           </Button>
                </Content>
            </Container>
            </View>
        );
    }
   nextScreen() {
     this.props.navigator.push({id:"Home"})

   }
}

Try Following: 尝试以下操作:

<Navigator
        style={{ flex:1 }}
        ref={(nav) => { navigator = nav; }}
        initialRoute={{id:"Login"}}
        renderScene={(route, navigator) =>
         {return this.renderScene(route, navigator)}}
      />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React Native + Firebase登录错误:未定义不是对象(正在评估“ this.props.navigator”) - React Native + Firebase signin Error: Undefind is not object (evaluating 'this.props.navigator') React Native错误:undefined不是对象(评估&#39;_this2.props.navigator.push&#39;) - React Native error: undefined is not an object (evaluating '_this2.props.navigator.push') React Native,NavigatorIOS,undefined不是一个对象(评估&#39;this.props.navigator.push&#39;) - React Native, NavigatorIOS, undefined is not an object (evaluating 'this.props.navigator.push') 反应本机。 未定义不是对象(评估“ this.props.navigator.push”) - React native. undefined is not object (evaluating 'this.props.navigator.push') React Native 中的堆栈导航器。 错误“undefined is not an object (evaluating this.props.navigation)” - Stack Navigator in React Native. Error "undefined is not an object (evaluating this.props.navigation)" 未定义不是对象(评估“ this.props.navigator.replace”) - Undefined is not an object (evaluating 'this.props.navigator.replace') undefined 不是 object(评估 'this.props = props') - undefined is not an object (evaluating 'this.props = props') React-Native expo 在React-Native Navigator中传递道具/状态 - Passing props / state in React-Native Navigator React Native 问题:未定义不是对象(评估&#39;this.props.navigator.push&#39;) - React Native Issue: undefined is not an object (evaluationg 'this.props.navigator.push') 当我尝试从一个页面导航到另一页面时,undefined不是对象(评估&#39;_this.props.navigator.push&#39;)是本机的 - undefined is not an object (evaluating '_this.props.navigator.push') react native , when i am trying to navigate from one page to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM