React Navigation check if previous screen exists

后端 未结 5 741
甜味超标
甜味超标 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 16:56

    As of React Navigation 5 you can use useNavigationState hook inside functional component this way:

    const routesLength = useNavigationState(state => state.routes.length);
    console.log('routesLength', routesLength);
    

    If routesLength > 1 then it is not the first screen in stack

    Or you can use navigation.canGoBack()

提交回复
热议问题