解决antd-pro页面刷新后数据丢失

一、刷新后数据消失

原因所在:数据存在modal的state当中,刷新的时候state数据丢失。

解决方法:将数据的id放入网页的路由中,每次进入页面的时候重新请求数据。

代码:

路由配置:

'/information/pageForm/:id':{
    component: dynamicWrapper(app, ['dispute'],() => import('../routes/Dispute/PageForm')),
},

从路由中读取数据:

const pathToRegexp = require('path-to-regexp');
const match = pathToRegexp('/information/pageForm/:id').exec(this.props.location.pathname);

读取到的数据会存在match这个数组当中。

页面跳转代码:
新增时:

this.props.dispatch(routerRedux.push('/information/pageForm/-1'));

编辑时:

this.props.dispatch(routerRedux.push(`/information/pageForm/${record.id}`));

猜你喜欢

转载自blog.csdn.net/Bonny722/article/details/81366287