Search code examples
react-nativereact-native-router-flux

react native router flux back to the initial screen from the sub scene


I'm trying to implement logout button on the profile page.

I have following routes defined.

<Router>
    <Scene initial  key='splashScreen' component={SplashScreen} title='Sayan' hideNavBar />
    <Scene key='loginScreen' component={LoginScreen} title='President Login' hideNavBar />
    <Scene key='drawer' component={NavigationDrawer} open={false}>
        <Scene key='drawerChildrenWrapper' hideNavBar>
            <Scene key='homeScreen' component={HomeScreen} title='Sayan' hideNavBar />
            <Scene key='createUserScreen' component={CreateUserScreen} title='Create a user' hideNavBar />   
            <Scene key='Profile' component={ProfileScreen} title='Profile' hideNavBar />
        </Scene>
    </Scene>
</Router>

What does the logout button handler look like, if i want to pop back to splashScreen or loginScreen scene?


Solution

  • This should close the current screen and show the loginScreen: Actions.popTo('loginScreen');

    Actions.pop closes current Scene. Actions.popTo is essentially two commands... Actions.pop() and Actions.loginScreen()