redux如何整合navigation



  • 描述

    项目采用react-redux统一状态管理,导航使用到react-navigation,我自己进行配置以后,获取不到dispatch等redux相关方法。

    界面能够正常跳转,但是获取不到dispatch等,无法操作redux进行管理的状态。

    相关整合代码

    整合文件
    enter description here

    root.js

    import React, { Component } from 'react';
    import { Provider } from 'react-redux';
    import store from './store/store';
    import App from './app';
    export default class Root extends Component {
        render() {
            return (
                <Provider store = {store} >
                    <App />
                </Provider>
            )
        }
    }
    

    app.js

    import AppNavigator from './appNavigator';
    export default class App extends Component {
    
        render() {
            return (
                <View style={{flex: 1}}>
                    <StatusBar
                        barStyle='light-content'
                        backgroundColor='transparent'
                        translucent={true}
                    />
                    <AppNavigator  />
                </View>
            )
        }
    }
    

    appNavigator.js

    import { StackNavigator } from 'react-navigation';
    import Splash from './pages/Splash';
    import Home from './pages/home';
    import Two from './pages/two';
    export default AppNavigator = StackNavigator({
            //导航
            Splash: {
                screen: Splash
            },
            Home: {
                screen: Home
            },
            Two: {
                screen: Two
            },
        },{
            initialRouteName: 'Splash', // 默认显示界面
            headerMode: 'none',
        }
    );
    

    @晴明



  • 问题已经解决,查看navigation集成react-redux 例子


登录后回复