Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 反应导航-重复导航_Reactjs_React Native_Redux_React Redux_React Navigation - Fatal编程技术网

Reactjs 反应导航-重复导航

Reactjs 反应导航-重复导航,reactjs,react-native,redux,react-redux,react-navigation,Reactjs,React Native,Redux,React Redux,React Navigation,我想知道当redux存储导航状态时,导航应该如何发生 短版: 如果redux存储未处于初始状态,则会安装一个屏幕,而不会在那里进行实际导航 详细说明: 现在,我可以(1)使用父导航器(在我的例子中是StackNavigator)提供的导航道具,或者(2)调度一个操作来导航 1:this.props.navigation.navigate('main') 2:this.props.navigateToMainAction() 减速器: const INIT_STATE = Nav.router.g

我想知道当redux存储导航状态时,导航应该如何发生

短版:

如果redux存储未处于初始状态,则会安装一个屏幕,而不会在那里进行实际导航

详细说明:

现在,我可以(1)使用父导航器(在我的例子中是StackNavigator)提供的导航道具,或者(2)调度一个操作来导航

1:
this.props.navigation.navigate('main')

2:
this.props.navigateToMainAction()

减速器:

const INIT_STATE = Nav.router.getStateForAction(
    NavigationActions.navigate({ routeName: 'login' })
);
const navReducer = (state = INIT_STATE, action) => {
    const newState = Nav.router.getStateForAction(action, state);
    return newState || state;
};
导航结构:

const authStack = StackNavigator({
    login: { screen: LoginScreen }
    ,forgottendPassword: { screen: LoginScreen }
}, {
    initialRouteName: 'login'
    ,headerMode: 'none'
});

const homeDrawer = DrawerNavigator({
    home: {
        screen: HomeScreen
        ,navigationOptions: { drawerLockMode: 'locked-closed' }
    }
}, {
    drawerPosition: 'right'
    ,drawerWidth: 300
    ,contentComponent: props => <HomeDrawerMenu {...props} />
});

const mainStack = StackNavigator({
    homeDrawer: {
        screen: homeDrawer
        ,navigationOptions: ({ navigation }) => ({
            header: <HomeMenu navigate={navigation.navigate} />
        })
    }
    ,partnerList: {
        screen: PartnerListScreen
        ,navigationOptions: ({ navigation }) => ({
            header: <PartnerListMenu navigation={navigation} />
        })
    }
}, {
    initialRouteName: 'homeDrawer'
});

const Nav = StackNavigator({
    auth: { screen: authStack }
    ,main: { screen: mainStack }
}, {
    initialRouteName: 'auth',
    headerMode: 'none',
});
负载时的当前动作顺序:

@@INIT
Offline/STATUS_CHANGED
persist/REHYDRATE
check_token <- Check if the user is logged in (in this case he is)
check_token_commit
Navigation/NAVIGATE <- The user is forwarded to main, when he is logged in
Navigation/NAVIGATE <- The user goes to the partnerList component
fetch_partner_list <- Action for fetching the partner list
Offline/BUSY
fetch_partner_list_commit
@@INIT
Offline/STATUS_CHANGED
persist/REHYDRATE
check_token <- Check if the user is logged in (in this case he is)
fetch_partner_list <- It's already fetching, but no navigate action was triggered yet
Offline/BUSY
check_token_commit
Navigation/NAVIGATE <- The user is forwarded to main, when he is logged in
Navigation/NAVIGATE <- The forwarding happens twice, for some reason
fetch_partner_list_commit
Navigation/NAVIGATE <- The user goes to the partnerList component
fetch_partner_list <- The only time it should be triggered
Offline/BUSY
fetch_partner_list_commit
@@INIT
脱机/状态\u已更改
持续/再水化

check_token该问题是由于不正确使用react导航造成的

我必须包装身份验证和主路由器,并在屏幕道具中传递根导航对象