问题描述:

I have set Initial root as LoginScreen in Navigator (component of react-native).

But after login I want DashboardScreen having drawer as initial root for navigation drawer present in DashboardScreen

In App.js for login initial root:

<Navigator

style={styles.container}

initialRoute={{id: 'LoginScreen'}}

renderScene={this.navigatorRenderScene}/>

In navigatorRenderScene() method, I have declared the different routes in app.

then how to add initial root as DashboardScreen after login success.

网友答案:

You can use a state to declare a initial route.

if() //check if user if connected
        this.state.initial = {id: 'DashboardScreen'}
else
        this.state.initial = {id: 'LoginScreen'}

and in your Navigator:

<Navigator
        style={styles.container}
        initialRoute={this.state.initial}
        renderScene={this.navigatorRenderScene}/>
相关阅读:
Top