如何修复 TypeError:undefined 不是对象(评估“state.routes”)

我正在关注 react 导航文档,react-navigation-redux-helpers 的文档,但总是向我抛出这个错误。此外,如果我删除了persistGate,错误会得到修复,但我需要保留一些数据,所以这不应该是一个选项


这是我的 store.js


import { createStore, applyMiddleware } from 'redux';

import { persistStore, persistReducer } from 'redux-persist';

import { AsyncStorage } from 'react-native';

import { createReactNavigationReduxMiddleware } from 'react-navigation-redux-helpers';


import Reducer from './reducers/index';


const persistConfig = {

    key: 'root',

    storage: AsyncStorage,

    blackList: [],

};


const AppReducer = persistReducer(persistConfig, Reducer);


const middleware = createReactNavigationReduxMiddleware(

    (state) => state.navigation,

);


export const store = createStore(AppReducer, applyMiddleware(middleware));

export const persistor = persistStore(store);

这是我的 app-with-state.js


import AppNavigator from './AppNavigator';


const AppNavigatorWithState = createReduxContainer(AppNavigator);


class ReduxNavigation extends React.Component {

    render() {

        const { state, dispatch } = this.props;


        return <AppNavigatorWithState navigation={state} dispatch={dispatch} />;

    }

}


const mapStateToProps = (state) => ({

    state: state.navigation,

});


export default connect(mapStateToProps)(ReduxNavigation);

这是我的 AppNavigator.js


const Main = createStackNavigator(

    {

        Home: Home,

        Movie: Movie,

        Category: Category,

    },

    {

        defaultNavigationOptions: {

            header: Header,

        },

    },

);



const TabNavigator = createBottomTabNavigator(

{

        Home: {

            screen: Main,

            navigationOptions: {

                tabBarIcon: <Icon icon='🏠' />,

            },

        },

        About: { screen: About },

        Lucky: { screen: Lucky },

        Profile: { screen: Profile },

    },

    {

        tabBarOptions: {

           activeTintColor: 'white',

           activeBackgroundColor: '#65a721',

        },

    },

);


//const App = createAppContainer(TabNavigator);


export default TabNavigator;

青春有我
浏览 275回答 2
2回答

小唯快跑啊

我知道为时已晚,但它应该可以帮助其他人:))在你的 mystore.js 中const middleware = createReactNavigationReduxMiddleware(&nbsp; &nbsp; (state) => state.navigation,)应该是这样的:const middleware = createReactNavigationReduxMiddleware(&nbsp; &nbsp; (state) => state.router,)

慕尼黑的夜晚无繁华

我也遇到了这个错误,我没有找到任何线索,然后卡住了。经过几个小时的调试,这是因为我犯了愚蠢的错误。这是我的错误案例:const&nbsp;customContent&nbsp;=&nbsp;({props})&nbsp;=>&nbsp;{&nbsp;}实际上,props不需要{}。只需调用(props)like 即可修复错误。这是正确的案例:const&nbsp;customContent&nbsp;=&nbsp;(props)&nbsp;=>&nbsp;{&nbsp;}{}打电话时请不要加props。希望它对像我这样出错的人有所帮助。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript