React Native 0.44 版本之后移除了Navigator,使用需要單獨(dú)引入react-native-deprecated-custom-components
1、npm install react-native-deprecated-custom-components --save
2、import Navigator from 'react-native-deprecated-custom-components';
3、用到的地方使用
<Navigator.Navigator
initialRoute={{ name: defaultName, component: defaultComponent }}
configureScene={(route) => {
return Navigator.Navigator.SceneConfigs.VerticalDownSwipeJump;
}}
renderScene={(route, navigator) => {
let Component = route.component;
return <Component {...route.params} navigator={navigator} />
}} />
4、千萬記得使用Navigator.Navigator,我一直直接使用<Navigator></Navigator>,總是報(bào)錯(cuò),
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
這表明沒有找到Navigator組件,查了好半天才找到問題所在。
5、或者使用這種方式:
import CustomerComponents, {Navigator} from 'react-native-deprecated-custom-components';
這樣使用的時(shí)候,依舊可以使用 <Navigator></Navigator>
2和5 對Navigator的兩種引用方式,es6中模塊化 'react-native-deprecated-custom-components' export defult 不是Navigator ,Navigator只是export ,因而第2步引用方式相當(dāng)于 給 export default 的起了一個(gè)別名叫做Navigator ,會(huì)導(dǎo)致第4步的錯(cuò)誤 。
es6 模塊化中規(guī)定, export default aaa,在import aaa時(shí),不需要加{},而如果是export aaa 在 inport aaa時(shí),則需要加{}
export default就是輸出一個(gè)叫做default的變量或方法,然后系統(tǒng)允許你為它取任意名字。