grahammendick / navigation

Scene-Based Navigation for React and React Native
https://grahammendick.github.io/navigation/
Apache License 2.0
571 stars 40 forks source link

How to celar trackCrumbTrail before navigating to a previous scene #768

Closed salisuabubakar closed 7 months ago

salisuabubakar commented 7 months ago

Hello, Thanks for your time. I have an app with four tabs. Each tab has multiple scenes to navigate to. When i navigate to a scene on a first tab and then leave that scene and click on the second that how can i clear the scene i navigated to from the first tab to the tab scene itself? Am not sure if it is clear.

Basically i have an app that users have to login before they book an appointment. After you book appointment you navigate back to the homeTab.js which containers the form to book the appointment. When i navigate to the bookappointment.js and without submitting the appointment form and then i press on logout button which is on another tab and after logout i used prop function to navigate to the homeTab.js but then i see the bookappointment.js form. How can i clear the book appointment form so that users who have logged out will not see the book bookappointment form but rather go straight to the homeTab.js.

Hopefully you understand my questions.

Thanks

grahammendick commented 7 months ago

You can register 2 different lists of scenes. One list for when the user is logged in and the other for when they're logged out. Then if the user logs out when they're on the 'appointment' scene, the Navigation router will navigate them to the first scene of the logged out stack (the home scene in this example).

<TabBar>
  <TabBarItem>
    <NavigationHandler stateNavigator={homeNavigator}>
      <NavigationStack>
        {loggedIn ? 
          <>
            <Scene stateKey="home"><Home /></Scene>
            <Scene stateKey="appointment"><Appointment /></Scene>
          </>
          : 
          <>
            <Scene stateKey="home"><Home /></Scene>
          </>}
      </NavigationStack>
    </NavigationHandler>
  </TabBarItem>
grahammendick commented 7 months ago

Thanks for the vid. The answer I gave will work for that

salisuabubakar commented 7 months ago

Thanks for the vid. The answer I gave will work for that

I can confirm its working perfect. Thanks soo much for this wonderfull library.