提交 0b64c728 authored 作者: vipcxj's avatar vipcxj

fix:解决刷新页面后model里数据丢失的问题

上级 a5da6143
......@@ -41,6 +41,7 @@
"react-markdown": "^3.3.3",
"react-router-4-compat": "^1.0.6",
"react-sizeme": "2.4.1",
"redux-persist": "^5.10.0",
"resolve-pathname": "^2.2.0",
"uuid": "^3.2.1",
"word-wrap": "^1.2.3",
......
......@@ -76,3 +76,8 @@ input, img {
width: 100%;
}
.globalSpin {
width: 100%;
margin: 40px 0 !important;
}
/* eslint-disable no-underscore-dangle */
import dva from 'dva';
import createLoading from 'dva-loading';
import moment from 'moment';
import persistReducer from 'redux-persist/lib/persistReducer';
import storage from 'redux-persist/lib/storage';
import { getHistory } from './services/route';
import { initApp } from './data/app';
import appModel from './models/app';
......@@ -11,11 +14,19 @@ import './index.css';
moment.locale('zh-cn');
const persistConfig = {
key: 'root',
storage,
};
const persistEnhancer = () => createStore => (reducer, initialState, enhancer) => createStore(persistReducer(persistConfig, reducer), initialState, enhancer);
// 1. Initialize
const app = dva({
history: getHistory({
basename: config.basename,
}),
extraEnhancers: [persistEnhancer()],
onError(error) {
// eslint-disable-next-line no-console
processError(error);
......
/* eslint-disable no-underscore-dangle */
import React from 'react';
import PropTypes from 'prop-types';
import { Router4Compat as Router } from 'react-router-4-compat';
import { LocaleProvider, Spin } from 'antd';
import zhCN from 'antd/lib/locale-provider/zh_CN';
import persistStore from 'redux-persist/lib/persistStore';
import { PersistGate } from 'redux-persist/integration/react';
import isString from 'lodash/isString';
import get from 'lodash/get';
import config from './utils/config';
......@@ -10,6 +15,10 @@ import App from './routes/app';
import { getMenus, getModuleInfo, getModuleLayout } from './data/modules';
import Monk from './routes/main/monk';
import styles from './index.css';
const Loading = <Spin size="large" className={styles.globalSpin} />;
const registerModel = (app, model) => {
// eslint-disable-next-line no-underscore-dangle
if (!(app._models.filter(m => m.namespace === model.namespace).length === 1)) {
......@@ -264,7 +273,11 @@ function RouterConfig({ history, app }) {
});
}
return (
<Router history={history} routes={routes} onError={processError} />
<PersistGate persistor={persistStore(app._store)} loading={Loading}>
<LocaleProvider locale={zhCN}>
<Router history={history} routes={routes} onError={processError} />
</LocaleProvider>
</PersistGate>
);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论