使iOS 安卓公用同一端口
1. 修改默認(rèn)的引導(dǎo)過程
- 將index.ios.js 和 index.andriod.js中的默認(rèn)內(nèi)容清空
- 創(chuàng)建一個(gè)用于裝載路由文件的js文件(app.js)
- 配置app.js文件 并在index.xx.xxx文件中導(dǎo)入裝載路由的文件
import root from './App/app'
2. 在頁面中創(chuàng)建一個(gè)導(dǎo)航欄
static navigationOptions = {
header: {
style:{backgroundColor:NavigationBackgroundColor},
tintColor:'white',
},
title: '分類',
}
3. RN頁面導(dǎo)航欄的跳轉(zhuǎn)辦法
cellOnclick(data) {
this.props.navigation.navigate('GoodList', { gcId: data.gcId, gcIdSearch:'gcIdSearch' })
}
注 : 若是想要在RN中跳轉(zhuǎn)到某個(gè)路由器 需要在router.js中聲明這個(gè)類
e.g. :
MainNavigator = StackNavigator( { AccountManagement: {screen: AccountManagement},//賬戶管理}
需要注意的是路由中聲明screen的時(shí)候需要確保需要的組件(Component)在聲明之前創(chuàng)建的
4. RN強(qiáng)行返回到指定頁面
back() {
const resetAction = NavigationActions.reset({
index: 0,
actions: [
NavigationActions.navigate({ routeName: 'Main'})
]
})
this.props.navigation.dispatch(resetAction)
};