简体   繁体   English

未定义不是对象(评估“ this.props.navigator.replace”)

[英]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.

相关问题 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不是对象(评估&#39;_this2.props.navigator.push&#39;) - React Native error: undefined is not an object (evaluating '_this2.props.navigator.push') 使用开关导航器:对象(评估&#39;_this.props.navigation.navigate&#39;)未定义 - using switch navigator: object (evaluating '_this.props.navigation.navigate') undefined 创建导航器时,未定义不是 object(评估 this.props.navigation.navigate) - Undefined is not an object (evaluating this.props.navigation.navigate) when creating navigator 为什么在react-native中使用this.props.navigator.replace再次渲染同一场景? - Why in react-native does the same scene gets render again using this.props.navigator.replace? React-Native Navigator“未定义不是对象(正在评估this.props.navigator)”错误 - React-Native Navigator “Undefined is not an object (evaluating this.props.navigator)” error 未定义不是 object(评估'_this.props) - Undefined is not an object (evaluating'_this.props) TypeError: undefined is not an object(评估'this.props = props') - TypeError: undefined is not an object (evaluating 'this.props = props') 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)"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM