I am using stack navigation in drawer navigation and it will add a new router when element clicker in drawer navigation

This is the top level navigation bar.

            import React ,{Component} from 'react'
            import { addNavigationHelpers } from 'react-navigation';
            import {DrawerNavigator} from 'react-navigation'
            import {connect} from 'react-redux'
            import DevicesPage from '../page/DevicesPage'
            import  HomeStackNavigation from './HomeStackNavigation'
            import ServerPage from '../page/ServerPage'
            import DrawerPage from '../page/DrawerPage'
            const {width,height} = Dimensions.get('window');
            const mapStateToProps = (state)=>({
                drawerNav : state.DrawerNavReducer
            });
            class DrawerNavigation extends Component{
                render(){
                    return( 
                        <Drawer
                        navigation={addNavigationHelpers({
                            dispatch: this.props.dispatch,
                            state : this.props.drawerNav
                        })}
                        />
                    );
                }
            }
            export const Drawer = DrawerNavigator({
                Home:{
                    screen : HomeStackNavigation
                },
                Devices:{
                    screen : DevicesPage
                },
                Server:{
                    screen : ServerPage
                }
            },{
                initialRouteName:'Home',
                drawerWidth: width - 100,
                drawerPosition: 'left',
                contentComponent: props =><DrawerPage {...props}/>
            })
            export default connect(mapStateToProps)(DrawerNavigation);

      

And this is my stack navigator, this is the first item in the drawer navigator.

            import React,{Component} from 'react';
            import {
                View
            } from 'react-native'
            import {StackNavigator} from 'react-navigation';
            import {addNavigationHelpers } from 'react-navigation';
            import {connect} from 'react-redux';
            import HomePage from '../page/HomePage'
            class HomeStackNavigation extends Component{
                render(){
                    return(
                        <StackNavigation navigation={
                        addNavigationHelpers({
                            dispatch: this.props.dispatch,
                            state : this.props.nav,
                        })}/>);
                }
            }
            export const StackNavigation = StackNavigator({
                Home:{
                    screen:HomePage
                }
            },{
                initialRouteName : 'Home',
                initialRouteParams :  {
                    chartType : 'BarChart'
                }
            })
            const mapStateToProps = (state)=>{
                return({
                    nav : state.HomeStackNavReducer,
                });
            }
            export default connect(mapStateToProps)(test);

      

when I first enter the test view it is the router which the key is "init". When I open the drawer, click the first item. It will add a new router. Finally a red screen appears. This is because I need some parameters for an initialized router and not a new router. so can you help me. And this is the first entry to the pageenter image description here

There are two routers when I entered it again enter image description here

+3


source to share





All Articles