Reputation: 1731
I'm using the t4t5/react-native-router and I'm having trouble trying to figure out how to remove the last route so that the user can't go back (after login).
Is there a way to reset the stack so the next route would be the root?
Note, I've also tried the React NavigatorIOS but it doesn't change the title on the new route (text is the same as initial route).
Upvotes: 2
Views: 3249
Reputation: 16790
There's a issue about changing title when using resetTo
: https://github.com/facebook/react-native/issues/476.
Here's another possible solution: use Navigator (not NavigatorIOS). Basically, in index.ios.js
we should do:
renderScene: function(route, nav) {
switch (route.id) {
case 'home':
return <Home navigator={nav}/>;
case 'login':
return <Login navigator={nav}/>;
case 'register':
return <Register navigator={nav}/>
default:
return (
<Login navigator={nav}/>
);
}
},
render: function() {
return (
<Navigator
style={{backgroundColor: '#fff'}}
initialRoute={{ id: "login" }}
renderScene={this.renderScene}
configureScene={(route) => {
if (route.sceneConfig) {
return route.sceneConfig;
}
return Navigator.SceneConfigs.FloatFromRight
}
}
/>
)
}
And if login is a success, in Login do this:
this.props.navigator.replace({ id: 'home' });
to replace current route so that user won't go back to Login.
An example can be found here.
Upvotes: 7