title: How to change initial screen after user is logged in in react native?
body: <p>I'm using <code>react-native router-flux</code> for navigation in my app.How do I change the initial screen for logged in users? Currently after successful login the user will direct to <code>firstScreen</code>. But after I close and re-open the app the initial screen will be login screen , because I've set it as initial within my <code>Main</code>. I want to show the <code>firstScreen</code> if a user exit from app with out log out.So how do I change according to the condition. I'm using <code>AsyncStorage</code> for saving the <code>userid</code>.But after closing the app and opening it again (without log out) the consoled o/p of <code>AsyncStorage</code> is undefined without login.Following is the code for <code>Main</code>.Please help me to do this.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>  
  
     import React, { Component } from 'react';
      import {KeyboardAvoidingView, View, ActivityIndicator, AsyncStorage} from 'react-native';
      import { Router, Scene, Actions, ActionConst } from 'react-native-router-flux';
  
      import LoginScreen from './LoginScreen';
      import RegisterScreen from './RegisterScreen';
      import FirstScreen from './FirstScreen';
      import ViewStatus from './ViewStatus';
      import UserVerification from './UserVerification';
  
      export default class Main extends Component{
        constructor() {
        super();
        this.state = { hasToken: false, isLoaded: false };
       }
  
       componentDidMount() {
          AsyncStorage.getItem('userid').then((token) =&gt; {
            this.setState({ hasToken: token !== null, isLoaded: true })
          });
        }
         async onPressLogout() {
    try {
     await AsyncStorage.removeItem('userid');
     Alert.alert('Logout Success!');
     Actions.loginScreen();
    } catch (error) {
     console.log('AsyncStorage error: ' + error.message);
    }
   }
       render(){
        console.log(this.hasToken);
          if (this.state.isLoaded) {
  
               return (
                       &lt;Router&gt;
         &lt;Scene key="root"&gt;
  
           &lt;Scene key="loginScreen"
            component={LoginScreen}
            animation='fade'
            hideNavBar={true}
            initial={true}
           /&gt;
         &lt;/Scene&gt;
        &lt;/Router&gt;
              )
            }
       else{
        return(
         &lt;Router&gt;
  
           &lt;Scene key="root"&gt;
  
          &lt;Scene key="firstScreen"
          component={FirstScreen}
          hideNavBar= {false}
          onRight={()=&gt;this.onPressLogout()}
              rightTitle={' Logout'}
           renderBackButton={()=&gt;(null)}
          animation='fade'
          /&gt;
  
               &lt;Scene key="viewStatus"
           component={ViewStatus}
           hideNavBar={false}
  
            /&gt;
              &lt;Scene key="userVerification"
          component={UserVerification}
          hideNavBar={true}
  
          /&gt;
          &lt;/Scene&gt;
         &lt;/Router&gt;
        );
         }
       }
      }</code></pre>
  </div>
  </div>
  </p>