0

我在使用带有抽屉导航的堆栈导航等反应导航时遇到问题

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;

根页面是 authcheck,它检查访问令牌并返回用户。

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();
			}
		})

但是当有访问令牌可用时,它没有显示任何错误,也没有导航到请求的页面。

此导航不会将我从 DrawerNavigator 重定向到我想要的页面...

如果有人知道请帮忙...

4

1 回答 1

1

这是由于参考

这个.prop

创建一个全局函数

 onAuthentication = (screenName) =>{

this.props.navigation.navigate(screenName)

};

然后在你的 fetch 函数中调用这个函数,比如

this.onAuthentication('updatesegregation') or this.onAuthentication('login')
于 2018-01-10T06:08:19.747 回答