Javascript antd分页组件';onChange';API don';当浏览器返回或前进时,不要调用
浏览器back或fore无法调用“onChange”API,因此页面列表无法根据当前页面进行更新Javascript antd分页组件';onChange';API don';当浏览器返回或前进时,不要调用,javascript,reactjs,react-router,antd,Javascript,Reactjs,React Router,Antd,浏览器back或fore无法调用“onChange”API,因此页面列表无法根据当前页面进行更新 onPageChange = (page, pageSize) => { const { dispatch } = this.props const param = { blogId: this.props.params.id, pageIdx: page, quantity: pageSize } dispatc
onPageChange = (page, pageSize) => {
const { dispatch } = this.props
const param = {
blogId: this.props.params.id,
pageIdx: page,
quantity: pageSize
}
dispatch(fetchIssues('getComments', param, ''))
hashHistory.push({
pathname: `/post/${this.props.params.id}`,
query: { pageIdx: page }
})
}
render() {
return <Pagination onChange={onPageChange} total={50} />
}
onPageChange=(页面,页面大小)=>{
const{dispatch}=this.props
常量参数={
blogId:this.props.params.id,
pageIdx:第页,
数量:页面大小
}
分派(fetchIssues('getComments',param','))
hashHistory.push({
路径名:`/post/${this.props.params.id}`,
查询:{pageIdx:page}
})
}
render(){
返回
}
首先,您需要考虑浏览器返回或前点击事件。该事件调用popstate
每次当前历史记录条目更改时(用户导航到新状态),都会触发popstate事件。当用户单击浏览器的后退/前进按钮,或者通过编程调用history.Back()
,history.Forward()
,history.go()
方法时,就会发生这种情况
在Javascript中
window.addEventListener('popstate',函数(事件)var r=confirm(“您按下了后退按钮!确定吗?!”)
如果将
onChange={onPageChange}
替换为onChange={this.onPageChange}
window.addEventListener('popstate', function(event) {
// The popstate event is fired each time when the current history entry changes.
if (r == true) {
// Call Back button programmatically as per user confirmation.
history.back();
// Uncomment below line to redirect to the previous page instead.
// window.location = document.referrer // Note: IE11 is not supporting this.
} else {
// Stay on the current page.
history.pushState(null, null, window.location.pathname);
}
history.pushState(null, null, window.location.pathname);
}, false);