以下错误的环境是:
React:15.4.2
ReactNative:0.40.0
1 Element type is invalid
ES5的导出导入语法:
module.exports = Page2;
var NaviBar = require('./NaviBar');
ES6的导入导出语法:
export default class Page2 extends Component
import NaviBar from './NaviBar';
Demo中使用了错误的导入方法
import { AppRegistry } from 'react-native';
import { FirstView } from './Demo/ViewDemo.js';
正确的是
import { AppRegistry } from 'react-native';
import FirstView from './Demo/ViewDemo.js'; //自定义的不能使用{}
Cannot read property 'navigator' of undefined
原因是:When you create components as ES6 classes, methods are not bound to instance automatically。就是在初始化的时候,方法没有绑定实例对象。
解决方案:goTo方法绑定实例对象
constructor(props, context) {
super(props, context);
this.goTo = this.goTo.bind(this);
}