【发布时间】:2017-03-29 10:23:42
【问题描述】:
我将参数从 react-router 的路由路径传递给组件,但在 this.props 对象中,'params' 不存在
const routes = (
<Router forceRefresh={true}>
<div>
<Route exact path="/" component={Firstpage}/>
<Route exact path="/projects" component={Projectslist}/>
<Route exact path="/projects/:projectId" component={Singleproject}/>
</div>
</Router>
);
这是我的组件:
class Singleproject extends React.Component{
constructor(props) {
super(props);
}
componentWillMount(){
window.document.title = "Wploper | Project title";
}
render(){
return(
<div>
<Mainheader/>
<div id="single-project-container" className="sheet-max-width">
<h2>{this.props.params}</h2>
</div>
<Mainfooter/>
</div>
);
}
}
并且对象(this.props)没有参数: enter image description here
【问题讨论】:
-
你使用的是哪个 react-router 版本?
-
同时粘贴您调用接收参数的路由的代码。
-
第四版。
-
我在构造函数中使用console.log对其进行测试
标签: reactjs react-router