From e2aeb7c927f85cf7aee9e33c0c343c235559eee2 Mon Sep 17 00:00:00 2001 From: xiaohu <448627663@qq.com> Date: Sat, 7 Jul 2018 13:20:35 +0800 Subject: [PATCH] set init route --- config/config.js | 3 +++ src/models/global.js | 20 +++++++++++++++++++- src/pages/index.js | 3 +++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/pages/index.js diff --git a/config/config.js b/config/config.js index 60fed500..a6300dcc 100644 --- a/config/config.js +++ b/config/config.js @@ -93,6 +93,9 @@ export default { }, alias: { components: path.resolve(__dirname, '../src/components/'), + utils: path.resolve(__dirname, '../src/utils/'), + assets: path.resolve(__dirname, '../src/assets/'), + common: path.resolve(__dirname, '../src/common/'), }, ignoreMomentLocale: true, theme: './src/theme.js', diff --git a/src/models/global.js b/src/models/global.js index 55841e16..b88e8dc3 100644 --- a/src/models/global.js +++ b/src/models/global.js @@ -1,3 +1,5 @@ +import router from 'umi/router'; +import { getAuthority } from 'utils/authority'; import { queryNotices } from '../services/api'; export default { @@ -31,6 +33,13 @@ export default { payload: count, }); }, + *init({ payload }, { put }) { + if (payload.hasAuthority) { + yield put(router.push('/User/Login')); + } else { + yield put(router.push('/Dashboard/Analysis')); + } + }, }, reducers: { @@ -55,12 +64,21 @@ export default { }, subscriptions: { - setup({ history }) { + setup({ history, dispatch }) { // Subscribe history(url) change, trigger `load` action if pathname is `/` return history.listen(({ pathname, search }) => { if (typeof window.ga !== 'undefined') { window.ga('send', 'pageview', pathname + search); } + if (pathname === '/') { + const author = getAuthority(); + dispatch({ + type: 'init', + payload: { + hasAuthority: author === 'guest' || !author, + }, + }); + } }); }, }, diff --git a/src/pages/index.js b/src/pages/index.js new file mode 100644 index 00000000..3c4c9034 --- /dev/null +++ b/src/pages/index.js @@ -0,0 +1,3 @@ +import React from 'react'; + +export default () =>
; -- GitLab