TypeError: undefined is not an object (evaluating 'routes[index].params.theme')
来源:2-8 TabNavigator精讲-3
liuxiaozhu
2018-07-07
老师这个怎么解决
写回答
2回答
-
CrazyCodeBoy
2018-07-09
确认下react-navigation的版本如果是2.0以上版本参考如下代码:
import {createDrawerNavigator, createStackNavigator,SafeAreaView,DrawerItems} from 'react-navigation'; import {createBottomTabNavigator, BottomTabBar} from 'react-navigation-tabs'; class TabBarComponent extends React.Component { constructor(props) { super(props); this.theme = { tintColor: props.activeTintColor, updateTime: new Date().getTime() } } render() { const {routes, index} = this.props.navigation.state; const {theme} = routes[index].params; if (theme && theme.updateTime > this.theme.updateTime) { this.theme = theme; } /** * custom tabBarComponent * https://github.com/react-navigation/react-navigation/issues/4297 */ return ( <BottomTabBar {...this.props} activeTintColor={this.theme.tintColor || this.props.activeTintColor} /> ); } } export const AppTabNavigator = createBottomTabNavigator({ Page1: { ...
00 -
r4ggjlx
2018-07-07
routes[index].params ===undefined?
032018-07-11
相似问题