How can I display the login page if the user is not authorized or a list of items?
I'm using react-native-router-flux
<Router>
<Scene key="user">
<Scene key="register1" component={RegisterStep1} title="register1"/>
<Scene key="register2" component={RegisterStep2} title="register2"/>
<Scene key="register3" component={RegisterStep3} title="register3"/>
<Scene key="login" component={Login} title="Login"/>
</Scene>
<Scene key="items" type={ActionConst.REPLACE}>
<Scene key="list" component={ItemList} title="Items list"/>
<Scene key="detail" component={ItemDetail} title="Item detail"/>
</Scene>
</Router>
is it right?
I should go to login Scene or items -> list Scene.
You can check if the user is authorized in the componentWillMount
or componentDidMount
lifecycle methods of your main component(The one that has the Router component) and call Actions.items()
after everything goes well. Otherwise go to the login screen.
Also I recommend two things:
-Put your scenes inside a root
scene as recommended by react-native-router-flux
-Set one of your screens as initial (with the prop of the scene: initial={true}
so that the user can see something before your lifecycle method does its work.