如何在 React Native 中切换到另一个模块?
How to switch to another module in react native?
刚刚实现了一个登录页面。
用户点击登录按钮后。
如何导航到我的主页模块?
代码应如下所示:
登录模块:
class MyClient extends Component{
render() {
return (
<View style={styles.container}>
<TouchableHighlight style={styles.button}
onPress={this.login.bind(this)}>
</TouchableHighlight>
</View>
);
}
login() {
//How to switch to home view here?
}
}
module.exports = MyClient;
主页模块:
class Home extends Component{
render() {
return (
<View>
<Text>This is home page</Text>
</View>
);
}
}
module.experts = Home;
我不想使用 navigator 这个组件,因为我认为主页模块和登录模块不应该是父子关系。
有没有办法在这两个页面之间切换?
你必须使用导航器。您可以尝试使用 "replace" 而不是 "push"。这样就可以实现组件之间的即时导航。
this.props.navigator.replace({
title: 'Home', component: Home
});
如果您想隐藏导航栏,可以使用 NavigatorIOS 组件的 "navigationBarHidden" 属性。
<NavigatorIOS navigationBarHidden = 'true' />
刚刚实现了一个登录页面。
用户点击登录按钮后。 如何导航到我的主页模块?
代码应如下所示:
登录模块:
class MyClient extends Component{
render() {
return (
<View style={styles.container}>
<TouchableHighlight style={styles.button}
onPress={this.login.bind(this)}>
</TouchableHighlight>
</View>
);
}
login() {
//How to switch to home view here?
}
}
module.exports = MyClient;
主页模块:
class Home extends Component{
render() {
return (
<View>
<Text>This is home page</Text>
</View>
);
}
}
module.experts = Home;
我不想使用 navigator 这个组件,因为我认为主页模块和登录模块不应该是父子关系。
有没有办法在这两个页面之间切换?
你必须使用导航器。您可以尝试使用 "replace" 而不是 "push"。这样就可以实现组件之间的即时导航。
this.props.navigator.replace({
title: 'Home', component: Home
});
如果您想隐藏导航栏,可以使用 NavigatorIOS 组件的 "navigationBarHidden" 属性。
<NavigatorIOS navigationBarHidden = 'true' />