【发布时间】:2015-09-21 08:24:03
【问题描述】:
我知道这是一个相当无证的功能,但由于 react-router 没有将道具传递给子路由组件的干净方法,我想使用上下文。
<Router history={history}>
<Route component={Application} path="/(:id)">
<IndexRoute component={EditDocument} />
</Route>
</Router>
class Application extends Component {
static childContextTypes = {
charts: PT.array.isRequired,
}
getChildContext() {
return { charts: this.getCharts() };
}
render() {
return <div>{this.props.children}</div>
}
}
class EditDocument extends Component {
static contextTypes = {
charts: PT.array.isRequired,
}
componentWillMount() {
this.context.charts === undefined
}
}
我现在使用 React 0.13。用0.14能解决吗?
【问题讨论】:
-
看看react-router#1857和react-router#1531这些问题可能是值得的
标签: reactjs react-router