From fc9565c157884007bdba4eb44882b5a9e5ee5bf6 Mon Sep 17 00:00:00 2001 From: Baorong Li Date: Mon, 24 Jun 2019 20:50:09 +0800 Subject: [PATCH 1/2] add a flag to detect refresh saving query times in model/app.js --- src/models/app.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/models/app.js b/src/models/app.js index e3895d9..0157f3e 100644 --- a/src/models/app.js +++ b/src/models/app.js @@ -69,9 +69,11 @@ export default { }, effects: { *query({ payload }, { call, put, select }) { - const { success, user } = yield call(queryUserInfo, payload) + // store isInit to prevent query trigger by refresh + const isInit = store.get('isInit') + if (isInit) return const { locationPathname } = yield select(_ => _.app) - + const { success, user } = yield call(queryUserInfo, payload) if (success && user) { const { list } = yield call(queryRouteList) const { permissions } = user @@ -96,6 +98,7 @@ export default { store.set('routeList', routeList) store.set('permissions', permissions) store.set('user', user) + store.set('isInit', true) if (pathMatchRegexp(['/', '/login'], window.location.pathname)) { router.push({ pathname: '/dashboard', @@ -117,6 +120,7 @@ export default { store.set('routeList', []) store.set('permissions', { visit: [] }) store.set('user', {}) + store.set('isInit', false) yield put({ type: 'query' }) } else { throw data From 3cb7f860860ad4b3408d46c6f9dbc898485fc223 Mon Sep 17 00:00:00 2001 From: Baorong Li Date: Sat, 29 Jun 2019 10:49:11 +0800 Subject: [PATCH 2/2] fix login jump to /enundefined --- package.json | 12 ++++++------ src/pages/login/model.js | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 46e2965..14ad5e5 100644 --- a/package.json +++ b/package.json @@ -49,12 +49,12 @@ "cross-env": "^5.2.0", "eslint": "^5.15.0", "eslint-config-react-app": "^4.0.0", - "eslint-plugin-flowtype": "^3.4.0", - "eslint-plugin-import": "^2.17.0", + "eslint-plugin-flowtype": "^3.11.0", + "eslint-plugin-import": "^2.18.0", "eslint-plugin-jsx-a11y": "^6.2.1", - "eslint-plugin-react": "^7.13.0", + "eslint-plugin-react": "^7.14.0", "eslint-plugin-react-hooks": "^1.6.0", - "husky": "^2.3.0", + "husky": "^2.7.0", "less-vars-to-js": "^1.3.0", "lint-staged": "^8.1.0", "mockjs": "^1.0.1-beta3", @@ -63,8 +63,8 @@ "stylelint": "^10.0.0", "stylelint-config-prettier": "^5.2.0", "stylelint-config-standard": "^18.3.0", - "umi": "^2.8.1", - "umi-plugin-react": "^1.9.1" + "umi": "^2.8.7", + "umi-plugin-react": "^1.9.6" }, "lint-staged": { "src/**/*.js": [ diff --git a/src/pages/login/model.js b/src/pages/login/model.js index dbbab85..e6d8c66 100644 --- a/src/pages/login/model.js +++ b/src/pages/login/model.js @@ -16,7 +16,7 @@ export default { const { from } = locationQuery yield put({ type: 'app/query' }) if (!pathMatchRegexp('/login', from)) { - if (from === '/') router.push('/dashboard') + if (['', '/'].includes(from)) router.push('/dashboard') else router.push(from) } else { router.push('/dashboard')