Use antd's table to develop a simple multi-page page. Multi-page pagination is included in the table. This is my first time using react@15.5.4, react-router@3.0.5, antd@2.0.9, When doing routing, you can add the page number route to the browser by clicking the page number on multiple pages, but you still return to the home page after refreshing, or even though the browser address has changed, you are still on the original page number page and there is no jump. Please help. Can you do me a favor? Below is the code part
1, Route distribution
class Index extends React.Component {
render () {
return (
<Router history={hashHistory}>
<Route path="/" component={App}>
<IndexRoute component={Login}></IndexRoute>
<Route path="/finance/:page" component={Finance}></Route>
</Route>
</Router>
);
}
}
2, on the Finance page, hashHistory.push()
handleTableChange = (pagination, filters, sorter) => {
this.fetch({
results: pagination.pageSize,
page: pagination.current,
// sortField: sorter.field,
// sortOrder: sorter.order,
...filters,
});
// console.log(pagination)
hashHistory.push(`/finance/${pagination.current}`);
}
3, table component in Finance
<Table
rowSelection={rowSelection}
columns={this.columns}
rowKey={record => record.wid}
dataSource={this.state.data}
pagination={this.state.pagination}
loading={this.state.loading}
onChange={this.handleTableChange}
/>
怪我咯2017-05-19 10:18:55
I solved it myself. I reloaded componentWillReceiveProps. In the end, the page will change when I refresh or roll back. I don’t know if this method is correct.
componentWillReceiveProps(nextProps) {
// console.log(nextProps);
const { pagination, filters } = this.state;
pagination.current = Number(nextProps.params.page);
this.setState({
pagination,
});
this.fetch({
size: pagination.pageSize,
page: pagination.current - 1,
startDate: this.state.startDate,
endDate: this.state.endDate,
...filters,
});
}