如何在注销时从native native-navigator中删除屏幕(卸载组件)?如何重新加载组件数据?

问题描述 投票:1回答:1

我在我的应用程序中使用react navigation v3,我在抽屉导航器中使用堆栈导航器,在点击注销时我导航到登录屏幕并清除用户存储,但每当我再次登录时,主要组件不会调用componentWillMount或componentDidMount方法,并显示以前加载的数据。这是我的代码>

const screens = {
  login: { screen: Login },
  dashboard: { screen: Dashboard },
  patientList:{screen:StackNav},
  headerComponent:HeaderComponent
 }

  const MyDrawerNavigator = createDrawerNavigator(
     screens,
      {
       initialRouteName: 'login',
      contentComponent: Sidebar
       }
     );

    App  = createAppContainer(MyDrawerNavigator);
    export default App;

StackNav ==

export default createStackNavigator({
     PatientList,
     PatientDetails
 });

注销功能==

  localStorageService.removeAllKeys().then((res) => {
    this.props.navigation.navigate(route, { isLogin: 'N' })
  });
react-native react-native-navigation react-native-component
1个回答
4
投票

把它放在抽屉导航器的navigationOptions中

unmountInactiveRoutes: true
© www.soinside.com 2019 - 2024. All rights reserved.