Skip to content Skip to sidebar Skip to footer

Have A Stack Navigator Always Render Initialroute

I'm building a react native app and I'm using react-navigation package. I have a tab navigator for the app and each tab has a stack navigator in it. Something like this: const Hom

Solution 1:

use initial route name like this in searchstack navigation like this

 {
    initialRouteName: 'Search',
  }

Solution 2:

You can use something like this inside every stack screen.

constSearch = ({ navigation }) => {
      useLayoutEffect(() => {
          const blur = navigation.addListener('blur', () => {
            navigation.popToTop();
          });
      }, []);
   }

This pops the stack to the initial screen everytime you navigate away.

More information here: https://reactnavigation.org/docs/navigation-events

Post a Comment for "Have A Stack Navigator Always Render Initialroute"