我使用的反应 - 路由器终极版安装了与反应路由器,终极版访问PARAMS
npm install --save [email protected]
实现像这样(https://github.com/ReactTraining/react-router/tree/master/packages/react-router-redux)
:
<Route path='/resource/:id' component={Resource}/>
我试图访问容器中的id参数,如下所示:
const mapStateToProps = (state, ownProps) => {
console.log(ownProps)
return {...state.resource, id: ownProps.params.id}
}
如react-router-redux文档所示。
我收到一个错误,指出ownProps.params是未定义的。所以这个工程:
const mapStateToProps = (state, ownProps) => {
return {...state.resource, id: ownProps.match.params.id}
}
当我登录ownProps,但是,我发现,ownProps.match.params.id包含我需要的ID。
这是执行改变还是我执行路线错误?由于
你能链接到react-router-redux文档吗? '路线'一直都是通过三个道具,'match','location'和'history'。 – Li357
https://github.com/reactjs/react-router-redux: 功能mapStateToProps(状态,ownProps){ 返回{ ID:ownProps.params.id, 滤波器:ownProps.location.query.filter }; } – zoopz