我是新来的反应本地人,并试图了解导航的使用....
找到了这个示例代码:
import React, { Component } from 'react';
import { AppRegistry, Text, Navigator } from 'react-native';
import Apple from './app';
import Orange from './app'
class AwesomeProject extends Component {
render() {
return (
<Navigator
initialRoute={{screen: 'Apple'}}
renderScene={(route, nav) => {return this.renderScene(route, nav)}}
/>
)
}
renderScene(route,nav) {
switch (route.screen) {
case "Apple":
return <Apple navigator={nav} />
case "Orange":
return <Orange navigator={nav} />
}
}
}
AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);
同时创建:
Apple.js
import React, { Component } from 'react';
import { View, Text, TouchableHighlight } from 'react-native';
export default class Apple extends Component {
render() {
return (
<View>
<Text>Apple</Text>
<TouchableHighlight onPress={this.goOrange.bind(this)}>
<Text>Go to Orange</Text>
</TouchableHighlight>
</View>
)
}
goOrange() {
console.log("go to orange");
this.props.navigator.push({ screen: 'Orange' });
}
}
但是由于某种原因我得到了这个错误...... 为什么呢?
这是我在模拟器中收到的错误消息
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Check the render method of `Navigator`.
instantiateReactComponent
index.android.bundle?platform=android&dev=true&hot=true&minify=false:23290:16
updateChildren
index.android.bundle?platform=android&dev=true&hot=true&minify=false:23171:58
_reconcilerUpdateChildren
index.android.bundle?platform=android&dev=true&hot=true&minify=false:22945:44
_updateChildren
index.android.bundle?platform=android&dev=true&hot=true&minify=false:23015:54
updateChildren