繁体   English   中英

当浏览器后退或前退时,不会调用antd分页组件'onChange'API

[英]antd Pagination Component 'onChange' API don't call when browser back or fore

浏览器无法向前或向后调用“ onChange” API,因此页面列表无法根据当前页面进行更新

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} />
}

首先,您需要考虑浏览器的后退或预点击事件。 该事件调用popstate每当当前历史记录条目更改(用户导航到新状态)时,都会触发popstate事件。 当用户单击浏览器的“后退/前进”按钮或以编程方式调用history.back()history.forward()history.go()方法时,就会发生这种情况。

用Java语言编写

window.addEventListener('popstate',function(event)var r = confirm(“您按下了Back按钮!确定吗?!”);

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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM