Search code examples
react-nativereact-navigation

react-navigation's weird behavior when back button is pressed on the second tab. (React Native)


I'm making app with using React Native. I have a tabNavigator.

If I go to second tab and press back button on the top navigation bar, It goes to first tab instead go back to previous screen.

I also noticed this behavior on sample app of react-navigation as well, so maybe it's made like that way.

Can't I make my tab navigator go previous screen regardless which tab I press the back button from?


Solution

  • This is indeed the default behavior of react-navigation.

    You can change it in the definition of your tab navigator, by specifying

    backBehavior: 'none'
    

    See the documentation for more.

    Example:

    const Tabs = TabNavigator({
      Tab1: {screen: Screen1},
      Tab2: {screen: Screen2},
      Tab3: {screen: Screen3}
    }, {
      backBehavior: 'none'
    });