我使用的反應 - 路由器終極版安裝了與反應路由器,終極版訪問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