React Navigation check if previous screen exists

后端 未结 5 742
甜味超标
甜味超标 2020-12-10 16:37

I am looking desperately for a possibility to check if a previous screen exists in ReactNavigation.

Using this.props.navigation.goBack() returns

5条回答
  •  星月不相逢
    2020-12-10 17:09

    It's completely working for me.... If you want to find out previous route/screen name from navigation stack in react native app so you can use this function.

    export const previousRouteName = (navigation) =>{
      let navRoutes = navigation.dangerouslyGetParent().state.routes;
      if (navRoutes.length >= 2){
        return navRoutes[navRoutes.length - 2].routeName
      }
      return navigation.state.routeName
    }
    

    How to use?

    previousRouteName(props.navigation);
    

    Hope you like and helpful to you K00L ;)

提交回复
热议问题