我想通过react-router将props从组件传递给子组件。我的流程是这样的:NaturalPersonList-> nav-> Naturalperson。 NaturalPersonList组件呈现导航组件, 在我的导航组件中,我使用react-router的Link模块链接到Naturalperson组件。我想将我的NaturalPersonList组件中的prop传递给Naturalperson,但由于Naturalperson没有显式渲染,我只是链接到它,我无法传递道具。 有什么方法可以实现这个}
NaturalPersonList:
var Nav=require('./nav.jsx');
var Router = require('react-router');
module.exports = React.createClass({
render: function render() {
return (<div><Nav nav1="Natural Person 1" nav2="Natural Person 2" nav3="Natural Person 3" nav4="Natural Person 4" section1="NaturalPerson" section2="NaturalPerson" section3="NaturalPerson" section4="NaturalPerson" firstName={this.props.firstName}/>
<Router.RouteHandler {...this.props}/></div>
);
}
});
导航组件:
module.exports = React.createClass({
displayName: 'nav',
render: function render() {
var activeClass = 'left-nav-selected';
return (
<section className='left-nav' id='left-nav'>
<div className='left-nav-title'>{this.props.name}</div>
<nav className='left-nav-links'>
<ul>
<li className='left-nav-link' id='nav-section1'>
<Link to=NaturalPerson params={{naturalPersonId: 1}} className={this.props.navSelection==='nav-section1'?activeClass:''}
activeClassName={activeClass}>{this.props.nav1}</Link>
</li>
</ul>
</nav>
</section>
);
}
});
NaturalPerson:
module.exports = React.createClass({
getInitialState :function() {
return{
readOnly : true
};
},
submit : function(){
this.setState({readOnly : false});
console.log(this.state.id);
},
save : function(){
this.transitionTo('/');
},
render: function render() {
return (<form action="/Output" method="POST" ><div id="container_suspects">
<input type="submit" value="Save" ></input>
<button type="button" onClick={this.submit} >Edit Details</button>
<div id="suspects_personal_details"><PD hidden="hidden" readOnly={this.state.readOnly}
firstName={this.props.firsName}/><br/><br/>
<PNS hidden="hidden" readOnly={this.state.readOnly}/><br/><br/>
<Email readOnly={this.state.readOnly} /><br/><br/></div>
<div id="suspects_address"><A readOnly={this.state.readOnly}/><br/><br/></div>
</div>
</form>
);
}
});
答案 0 :(得分:0)
如果我正确理解你。 你可以从Link发送道具:
<Link to=NaturalPerson params={{naturalPersonId: 1}}
className={this.props.navSelection==='nav-section1'?activeClass:''}
params={params: {dictionary}}
activeClassName={activeClass}>
{this.props.nav1}
</Link>