search

Home  >  Q&A  >  body text

javascript - react routing issues about antd multi-page pagination

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}
/>
PHPzPHPz2774 days ago1073

reply all(2)I'll reply

  • 怪我咯

    怪我咯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,
            });
        }

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-19 10:18:55

    Where is your setState that triggers react update?

    reply
    0
  • Cancelreply