Javascript 未定义不是对象';这个.props.route.push';(本地反应)

Javascript 未定义不是对象';这个.props.route.push';(本地反应),javascript,ios,navigation,react-native,Javascript,Ios,Navigation,React Native,我正在使用 但是,我收到一条错误消息,读取未定义不是对象(评估'this.props.route.push')。我不知道如何修复此问题,以便成功导航到新视图 LoginWrapper.js var React = require('react-native'); var Parse = require('parse/react-native').Parse; var ParseReact = require('parse-react/react-native'); var AppWra

我正在使用

但是,我收到一条错误消息,读取
未定义不是对象(评估'this.props.route.push')
。我不知道如何修复此问题,以便成功导航到新视图

LoginWrapper.js

 var React = require('react-native');
 var Parse = require('parse/react-native').Parse;
 var ParseReact = require('parse-react/react-native');

 var AppWrapper = require('./AppWrapper');
 var Routes = require('../Routes')

 var {
  TouchableHighlight,
  Text,
  TextInput,
  View,
 } = React;

 var LoginWrapper = React.createClass({
  mixins: [ParseReact.Mixin],

 getInitialState: function() {

  return {
  error: null,
  signup: false

  };
 },

 observe: function() {
  return {
  user: ParseReact.currentUser
  };
 },

 updateUsername: function(text) {
  this.setState({username: text}); 
 },

 gotoProfile: function(){
  this.props.route.push(Routes.Profile());
  },
updatePassword: function(text) {
this.setState({password: text}); 
 },

 render: function() {
  if (this.data.user) {
  return (
    <View style={{marginTop:100}}>
      <TouchableHighlight onPress={this.logOut}>
        <Text>Logout</Text>
      </TouchableHighlight>
      <TouchableHighlight onPress={this.gotoProfile}>
        <Text>Profile</Text>
      </TouchableHighlight>
      <AppWrapper />
    </View>
  );
}
return (
  <View>
    <View>
      {
        this.state.error ?
        <View><Text>{this.state.error}</Text></View> :
        null
      }
      <View style={{marginTop:200}}>
        <Text>Username</Text>
        <TextInput style={{height: 40, borderColor: 'gray', borderWidth: 1}} value={this.state.username} onChangeText={this.updateUsername} />
      </View>
      <View>
        <Text>Password</Text>
        <TextInput style={{height: 40, borderColor: 'gray', borderWidth: 1}} value={this.state.password} onChangeText={this.updatePassword} />
      </View>
      <View>
        <TouchableHighlight onPress={this.submit}>
          <Text>{this.state.signup ? 'Sign up' : 'Log in'}</Text>
        </TouchableHighlight>
      </View>
      <View>
        <TouchableHighlight onPress={this.toggleSignup}>
          <Text>{this.state.signup ? 'log in' : 'sign up'}</Text>
        </TouchableHighlight>
      </View>
    </View>
  </View>
);
},

submit: function() {
var self = this;
var username = this.state.username;
var password = this.state.password;
if (username.length && password.length) {
  if (this.state.signup) {
    console.log('signup');
    var u = new Parse.User({
      username: username,
      password: password
    });
    u.signUp().then(function() {


      self.setState({
        error: null
      });
    }, function() {
      self.setState({
        error: 'Invalid account information'
      });
    });
  } else {
    Parse.User.logIn(username, password).then(function() {
      self.setState({
        error: null
      });
    }, function() {
      self.setState({
        error: 'Incorrect username or password'
      });
    });
  }
 } else {
  this.setState({
    error: 'Please enter all fields'
  });
 }
},

logOut: function() {
 Parse.User.logOut();
}, 

  toggleSignup: function() {
    this.setState({
    signup: !this.state.signup
    });
   }

});

module.exports = LoginWrapper;

您可以从
console.log()
-ing
this
this.props
this.props.route
开始查看哪一个是未定义的。好的,我刚刚做了
this.props.route
未定义。我看不到
this.props
(和
this.props.route
在哪里定义/初始化);您是否有类似于'props:{route:[]},'over
gotoProfile:…
?您能否向我们展示父组件,或者该组件在何处/如何接收此.props.route?谢谢。@Kenney不,我没有这个定义。我不确定我会在定义中加入什么。
class Routes {
static register(name, handler) {
 if (this.handlers == null) this.handlers = {}
  this.handlers[name] = handler
 }
static get(name, params) {
 if (this.handlers[name] == null) throw new Error('unknown route')
 return this.handlers[name](params)
}
static Login() {
 return {
  component: require('./components/LoginScreen'),

  title: 'Login',
  titleStyle: {
  color: '#ddd',
  fontSize: 22
  }
 }
}
static Profile() {
return {
  component: require('./components/ProfileScreen'),
  title: 'Profile',
  titleStyle: {
color: '#ddd',
fontSize: 22
}
}
}

}

module.exports = Routes