元素类型无效:应为字符串或 class/function 但得到的是:对象。

Element type is invalid: expected a stringor a class/function but got: object.

我在使用 NavigatorIOS 时遇到了一些问题。 如果我将我的组件放在初始路由中,它工作得很好,但如果我尝试从另一个组件访问它,它会给我这个错误:

元素类型无效:应为字符串(对于内置组件)或 class/function(对于复合组件)但得到:对象。检查 'NavigatorIOS'.

的渲染方法

代码如下:

import React, { Component, PropTypes } from 'react';
import Dimensions from 'Dimensions';
import {
  AppRegistry,
  StyleSheet,
  Image,
  TouchableHighlight,
  NavigatorIOS,
  FadeInView,
  Text,
  View
} from 'react-native';
import Menu from './Menu.ios';


class Home extends React.Component {
  constructor(props, context) {
    super(props, context);
    this.onForward = this.onForward.bind(this);
  }

  onForward(Menu){
    this.props.navigator.push({
      component: Menu,
      title: 'Menu',
      navigationBarHidden: true,
    });
  }

  render() {
    return (
      <View style={styles.container}>
        <Image
          style={styles.img}
          source={require('./img/scrittaNera.png')}
          onLoadStart={(e) => this.setState({loading: true})}
          />
        <TouchableHighlight style={styles.button} onPress={this.onForward.bind(this)}>
          <Text style={styles.buttonText}>Get Inspired</Text>
        </TouchableHighlight>
      </View>
    );
  }
}

只需从中删除菜单 onForward(Menu) {.

参数 Menu 隐藏了使用 import Menu from './Menu.ios'; 导入的组件。