1. 程式人生 > >解決antd-pro頁面重新整理後資料丟失

解決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}`));