我正在使用嵌套导航抽屉>标签>堆栈导航器。
导航器正在工作,但是当我点击标签项时,它会抛出以下错误
undefined不是对象(评估' _ref4.route') _getOnPress TabView.js:110:44 _handleOnPress TabBarTop.js:127:31 onPress TabBar.js:466:33 _callTimer JSTimers.js:156:15 callTimers JSTimers.js:411:17 __callFunction MessageQueue.js:302:47 MessageQueue.js:116:26 __守护 MessageQueue.js:265:6 callFunctionReturnFlushedQueue MessageQueue.js:115:17
我被困在这里我尝试了许多但没有成功
这是我的代码
DrawerNav.js
import React, { Component } from 'react';
import { DrawerNavigator} from 'react-navigation';
import Icon from "react-native-vector-icons/FontAwesome";
import stackNav from './stackNav';
const Drawer = DrawerNavigator({
DrawerItem1: {
screen: stackNav,
navigationOptions: {
drawerLabel: "Drawer Item 1",
drawerIcon: ({ tintColor }) => <Icon name="rocket" size={24} />
},
},
DrawerItem2: {
screen: stackNav,
navigationOptions: {
drawerLabel: "Drawer Item 2",
drawerIcon: ({ tintColor }) => <Icon name="rocket" size={24} />
},
}
});
export default Drawer;
TabNav.js
import React, { Component } from 'react';
import { TabNavigator, TabView } from 'react-navigation'
import Icon from "react-native-vector-icons/FontAwesome";
import MainScreen from './screens/MainScreen';
const tabNav = TabNavigator({
TabItem1: {
screen: MainScreen,
navigationOptions: {
tabBarLabel:"Tab One",
tabBarIcon: ({ tintColor }) => <Icon name={"glass"} size={30} color={tintColor} />
}
},
TabItem2: {
screen: MainScreen,
navigationOptions: {
tabBarLabel:"Tab Two",
tabBarIcon: ({ tintColor }) => <Icon name={"glass"} size={30} color={tintColor} />
}
},
TabItem3: {
screen: MainScreen,
navigationOptions: {
tabBarLabel:"Tab Three",
tabBarIcon: ({ tintColor }) => <Icon name={"glass"} size={30} color={tintColor} />
}
}
///... add more tabs here
}, {
tabBarPosition: 'bottom',
tabBarOptions: {
activeTintColor: '#222'
},
});
export default tabNav;
stackNav.js
import React, { Component } from 'react';
import { TouchableOpacity } from 'react-native';
import { StackNavigator} from 'react-navigation'
import IOSIcon from "react-native-vector-icons/Ionicons";
import DetailScreen from './screens/DetailScreen';
import MainScreen from './screens/MainScreen';
import tabNav from './tabNav'
const stackNav = StackNavigator({
Main: {
screen: tabNav,
navigationOptions:({navigation}) => ({
title: "Main",
headerLeft:(
<TouchableOpacity onPress={() => navigation.navigate("DrawerOpen")}>
<IOSIcon name="ios-menu" size={30} />
</TouchableOpacity>
),
headerStyle: { paddingRight: 10, paddingLeft: 10 },
})
},
Detail: {
screen: DetailScreen,
navigationOptions: (props) => ({
title: "Detail",
})
}
})
export default stackNav;
答案 0 :(得分:1)
我与TabNavigator有同样的错误。
我也执行了官方反应导航示例(https://github.com/react-community/react-navigation/blob/master/examples/NavigationPlayground/js/SimpleTabs.js)但没有成功(同样的错误)。
我的猜测是,这是最新版本的Expo / React Native的错误。
您使用的是哪个版本?
我正在使用:
"dependencies": {
"expo": "^22.0.2",
"react": "16.0.0-beta.5",
"react-native": "^0.49.5",
"react-navigation": "^1.0.0-beta.20"
}
已确认:从Create React Native App中弹出可解决此问题。 因此,它似乎是Create React Native App或Expo的一个错误。