React Native 0.44版本后,Navigator使用

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)允許你為它取任意名字。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容