TypeError: undefined is not an object (evaluating 'routes[index].params.theme')

来源:2-8 TabNavigator精讲-3

liuxiaozhu

2018-07-07

http://img.mukewang.com/szimg/5b4041940001e04414820593.jpg

老师这个怎么解决

写回答

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: {
    ...


0
0

r4ggjlx

2018-07-07

routes[index].params ===undefined?

0
3
liuxiaozhu
回复
CrazyCodeBoy
第一次加载的时候,确实是 undefined。我想知道第一次加载时,在哪里配置传入这个 params ?
2018-07-11
共3条回复

React Native技术精讲与高质量上线App开发

一个真实的上线项目,一次完整的开发过程,全面掌握React Native技术

1577 学习 · 727 问题

查看课程