導航後經過this.props.history.push
我沒有在component
中獲得route params
。在導航via react-router-4後未得到路由參數
我有兩個路線上呈現的單個component
。
因此,從一條路線到另一條是component update
,我沒有得到它的route params
。
如果刷新頁面,我得到的route params
this.props.history.push(`/pois/select/${lastAction.payload.poiID}`)
我的路由組件。
class Routes extends React.Component {
render() {
return <div>
<Switch >
<Route exact path="/pois/" component={ POIS } mode='view' />
<Route exact path="/pois/select/:poiID" component={ POIS } mode='select' />
<Route exact path="/pois/create" component={ POIS } mode='create'/>
<Route exact path="/pois/update/:poiID" component={ POIS } mode='update'/>
</Switch>
</div>;
}
在哪裏打印params的名稱?使用'componentWillReceiveProps'生命方法並使用'console.log(nextProps.params)'它會打印值。這樣'componentWillReceiveProps(nextProps){ \t的console.log(nextProps.params) }' –
@MayankShukla 我可以看到的URL更新,在組件控制檯記錄表明'this.props.match.params'是空對象'{}' –
@MayankShukla 我可以在'componentWillReceiveProps'中看到參數,但是在'componentWillUpdate'調用的函數中看不到然後我想在執行前檢查模式是否發生了變化,'ajax'所以我需要'prevprops' –