Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 416
Bright Lee Avatar asked May 11 '26 23:05

Bright Lee


1 Answers

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'
});
like image 119
Kraylog Avatar answered May 13 '26 13:05

Kraylog



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!