简体   繁体   中英

React Native DrawerNavigator in Stack navigator is not working

I have trouble using the react-navigation like stack navigation with drawer navigation

 const Drawerstack = DrawerNavigator({ updatesegregation : { screen: UpdateSegregation }, listoffers : { screen: ListOffers }, mypurse : { screen: MyPurse }, myoffers : { screen: MyOffers }, segregationhistory : { screen: SegregationHistory }, ranking : { screen: Ranking }, updates : { screen: Blogs }, contactus : { screen: ContactUs }, termsandconditions : { screen: TermsAndConditions }, instruction : { screen: Instructions }, profile : { screen: Profile }, segregationtips : { screen: SegregationTips }, faqs : {screen: Faqs }, },{ contentComponent: NavigationDrawer, }) const Index = StackNavigator({ authcheck : { screen: AuthCheck }, login: { screen: Login }, registration : { screen: Registration }, profileedit : { screen: ProfileEdit }, socialregistration : { screen: SocialRegistration }, forgotpassword : { screen: ForgotPassword }, drawerstack: { screen: Drawerstack }, }, { headerMode: 'none' }); export default Index; 

the root page is authcheck which checks the access token and return the user.

 fetch(url.main + 'version' + url.transform, { method: 'GET', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' } }).then((response) => response.json()) .then((responseData) => { //alert(JSON.stringify(responseData)) if(responseData.version[0].version_code == Version){ AsyncStorage.getItem('User').then((value) => { //alert(JSON.parse(value)); var tmpValue = JSON.parse(value); if (tmpValue !== null) { this.props.navigation.navigate("updatesegregation"); }else{ this.props.navigation.navigate('login'); } }) }else{ this.PopupDialog.show(); } }) 

But when there is access token availabe then it didn't show any error an also it didn't navigate to the requested page.

This navigation is not redirecting me to the page i want from the DrawerNavigator...

if anyone knows please help...

This is due to reference

this.prop

create a global function

 onAuthentication = (screenName) =>{

this.props.navigation.navigate(screenName)

};

and then call this function inside ur fetch function like

this.onAuthentication('updatesegregation') or this.onAuthentication('login')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM