当前位置 : 主页 > 网页制作 > React >

reactjs – React Native StackNavigator initialRouteName

来源:互联网 收集:自由互联 发布时间:2021-06-15
在React Native Navigation库中’react-navigation’ 我如何通过AsyncStorage设置StackNavigator initialRouteName? function getInitialScreen() { AsyncStorage.getItem('initialScreen') .then(screenName = { return (screenName) ? screen
在React Native Navigation库中’react-navigation’

我如何通过AsyncStorage设置StackNavigator initialRouteName?

function getInitialScreen() {
    AsyncStorage.getItem('initialScreen')
        .then(screenName => {
            return (screenName)
                ? screenName
                : 'Login';
        })
        .catch(err => {});
}

const Navigator = StackNavigator({
    Splash: { screen: Splash },
    Login: { screen: Login },
    WebPage: { screen: WebPage }
}, {
    initialRouteName: getInitialScreen()
});
我也有这个问题,目前唯一的好解决方案是以下示例:

const RootNavLogged = StackNavigator({
     ...
  },{
     initialRouteName : 'Home'
  });

  const RootNav = StackNavigator({
     ...
  },{
     initialRouteName : 'Login'
  });

  class App extends Component {
     render(){
         if (this.props.userLogged == true ){
            return (
               <RootNavLogged/>
            ) 
          } else {
             return(
                <RootNav/>
              ) 
          }
     }
 }
网友评论