在React Native Navigation库中’react-navigation’ 我如何通过AsyncStorage设置StackNavigator initialRouteName? function getInitialScreen() { AsyncStorage.getItem('initialScreen') .then(screenName = { return (screenName) ? screen
我如何通过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/> ) } } }