[英]NavigatorIOS error in React-Native?
I'm currently trying to use a NavigatorIOS to navigate from my index ios page in my React-Native app to another page. 我目前正在尝试使用NavigatorIOS从我的React-Native应用程序中的索引ios页面导航到另一个页面。 However, when I do so I'm getting this error and the next page fails to load:
Warning: Failed propType: Invalid prop 'initialRoute.component' of type 'object' supplied to 'NavigatorIOS', expected 'function'.
但是,当我这样做时,出现此错误,下一页无法加载:
Warning: Failed propType: Invalid prop 'initialRoute.component' of type 'object' supplied to 'NavigatorIOS', expected 'function'.
I'm pretty sure I have implemented this in the exact same way successfully in the past, but I may be missing something--any feedback greatly appreciated! 我敢肯定,过去我已经以完全相同的方式成功实现了此功能,但是我可能会遗漏某些东西-感谢任何反馈!
Relevant code in index.ios.js: index.ios.js中的相关代码:
onLoginPressed() {
return (
<React.NavigatorIOS
style={styles.container}
initialRoute={{
title: 'Home',
component: Home,
}}/>
);
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome!
</Text>
<TouchableHighlight
onPress={() => {this.onLoginPressed()}}
activeOpacity={75 / 100}
underlayColor={"rgb(210,210,210)"}>
<Text>Login</Text>
</TouchableHighlight>
</View>
);
} } }}
Relevant code in Home: 主页中的相关代码:
class Home extends Component {
constructor(props) {
super(props);
this.state = { }
}
render() {
console.log('loaded here'); //this is never being called
return (
<View>
<Text
style={{
color: 'black',
fontSize: 16,
fontWeight: 'normal',
fontFamily: 'Helvetica Neue',
}}>
My Text
</Text>
</View>
)
}
}
export default Home
You need to have you NavigatorIOS and your initial route at the root of the application: 您需要在应用程序的根目录中拥有NavigatorIOS和初始路径:
class App extends Component {
render() {
return (
<NavigatorIOS
style={styles.container}
initialRoute={{
title: 'Home',
component: Home,
}}/>
)
}
}
onLoginPressed
should push the new route to the route stack: onLoginPressed
应该将新路由推送到路由堆栈:
onLoginPressed () {
this.props.navigator.push({
component: Login,
title: 'Login'
})
}
I've set up a working example with your code here . 我在这里用您的代码建立了一个工作示例。
https://rnplay.org/apps/Cl8aPQ https://rnplay.org/apps/Cl8aPQ
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.