【发布时间】:2016-08-23 20:06:24
【问题描述】:
这似乎是一个简单的解决方案(因为它对我来说很直观),但我找不到任何可行的解决方案。
这是我的 Navigator - 渲染方法代码:
render() {
return (
<Navigator initialRoute={{title:'Games', component:Games}}
configureScene={() => {
return Navigator.SceneConfigs.FloatFromRight;
}}
renderScene={(route, navigator) =>
{
if (route.component) {
return React.createElement(route.component, {navigator});
}
}
} />
);
}
这是我传递道具的方式:
this.props.navigator.push({title: 'MainActivity', component:MainActivity, gameKey:key, passProps:{title:'bla'}});
这是我想要获取这些道具的 MainActivity。
我试过了:
this.props.route.gameKey,
this.route.gameKey,
this.props.gameKey
这两种方法都不起作用,我知道我可能应该以另一种方式专门通过 renderScene 传递这些道具。可能是通过 createElement 传递路线?
请帮忙。
问题更严重,因为我已经通过 Navigator 将道具从一个活动传递到另一个活动。
所以,每次你需要的任何东西(从任何活动到任何活动)都在使用时传递的解决方案
return React.createElement(route.component, {navigator, route});
感谢@stereodenis。
在任何活动中像这样推送后:this.props.navigator.push({title: 'MainActivity', component:MainActivity, gameKey:key, passProps:{title:'bla'}});
然后通过以下方式访问它们:this.props.route.gameKey
为了完全清楚 - 现在可以访问路由,因为每次 U 推送时都会在 createElement 中传递 {navigator, route},所以这是另一个道具。
【问题讨论】:
标签: react-native