如何从新路线上的passProps获取参数?来自' Home'单身'确认值被解析而不确定如何在single.js上检索它们?
//index.ios.js
class AwesomeNativeBase2 extends Component {
renderScene(route, navigator) {
if(route.name == 'single') {
return <Single navigator={navigator} />
}
if(route.name == 'home') {
return <Home navigator={navigator} {...route.passProps} />
}
if(route.name == 'update') {
return <Update navigator={navigator} {...route.passProps} />
}
}
render() {
return (
<View style={styles.container}>
<Navigator
initialRoute={{name: 'home'}}
renderScene={this.renderScene.bind(this)}
/>
</View>
);
}
}
//home.js
class Home extends Component {
navigate(routeName, property) {
this.props.navigator.push({
name: routeName,
passProps: {
id: property
}
});
}
//single.js
class Single extends Component {
render() {
console.log(this.props.navigator.pop());
答案 0 :(得分:0)
正如其他路线所做的那样,按以下方式添加
renderScene(route, navigator) {
if(route.name == 'single') {
return <Single navigator={navigator} {...route.passProps}/>
}
....
}
在Single
组件内,访问passProps
的属性this.props.id