我想将一些道具传递给 IndexRoute 上的组件。下面是我的代码片段:
render(root: Element) {
const { store, params } = this as any;
ReactDOM.render(
<Provider {...{ store }} >
<Router history={browserHistory}>
<Route path={window.location.pathname} component={App}>
<IndexRoute component={Step1} />
<Route path="step1" component={() => (<Step1 params={params} />)} />
<Route path="step1" component={() => (<Step2 params={params} />)} />
</Route>
</Router>
</Provider>
, root);
}
//App Component
import * as React from 'react';
export var App: any = ({children}) => (
<div>
<div>{children}</div>
</div>
)
在初始加载时,我可以将步骤 1 作为子项加载,但我想将一些道具从路由部分传递到组件。
我怎样才能得到这个?
请指导我。
谢谢,
维杰
使用克隆元素cloneWithProps()
var newStep1 = cloneWithProps(Step1, {prop1: 'value', prop2: 'value'});// add props
并将其传递给<IndexRoute />
<IndexRoute component={newStep1} />
这应该有效..
参考 https://facebook.github.io/react/docs/clone-with-props.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)