简体   繁体   中英

How navigate from loginscreen after clicking on logout button in react native?

i'm trying to implement a logout functionality in react native.The users will land to homescreen after logged in , which contains a side bar . Logout button is within the side bar.I'm using stack navigator from react-navigation for navigating from one screen to another.I've tried like the below ,but there is a mistake it will direct to a blank screen when clicked on logout button.

onPressLogout(){
     AsyncStorage.removeItem('userdetail');
    this.props.navigation.navigate('LoginScreen');
    alert('You have been logged out.');
}

Currently i'm writing this code within homescreen . Where do i write the code for logout ?Does it be within Sidebar ?Also how to navigate Please help.

Updated

  const MainNavigator = TabNavigator({
         login: {screen: LoginScreen},
         register: { screen : RegisterForm },
  },

     {
  tabBarPosition: 'bottom',
  animationEnabled: true,
  color:"#aa4a00",
  tabBarOptions: {
    labelStyle: {
      fontSize: 15,
      fontFamily: 'HelveticaNeueBd',
      color: '#4B4C4B',
      backgroundColor: '#ffffff'
    },
    indicatorStyle : {
      backgroundColor: '#aa4a00'
    },
    style : {
      borderBottomColor: '#ebcccc',
     // borderBottomWidth: 10,
    },
    tabStyle: {
    activeBackgroundColor : "#aa4a00",
    inactiveBackgroundColor: '#dddddd',
    upperCaseLabel: false
  }
  }
     });
const StackScreens = StackNavigator({
    Main: {
        screen: MainNavigator,
    },
    CourseListing:{screen: CourseListing},
    Home: {screen: HomeScreen},
    EconomicNews: {screen: EconomicNews},
    EconomicDetails: {screen: EconomicDetails},
    CategoryDetail: {screen: CategoryDetail},
    DetailedView: {screen: DetailedView},
    IndividualSection: {screen: IndividualSection},
    Mcq:{screen: Mcq},
    QASection: {screen: QASection}
})

export const MyDrawer = DrawerNavigator({
   Home: {
     screen: StackScreens,
  },
  Profile: {
      screen: Profile
  },
  FAQ: {
      screen: Faq
  },
  LogOut: {
      screen: LogOut
  }
});

this.props.navigation.navigate('LoginScreen'); should change to this.props.navigation.navigate('MainNavigator'); or this.props.navigation.navigate('login');

Because you call your LoginScreen 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