From 81774c23d894191b8295bb30aadbf3f7f5cf0a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Thu, 5 Jul 2018 18:40:16 +0800 Subject: [PATCH] rebase: rebase v2 --- src/router.js | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/router.js b/src/router.js index c3db6fcb..bfc78e82 100644 --- a/src/router.js +++ b/src/router.js @@ -1,39 +1,52 @@ import React from 'react'; import { routerRedux, Route, Switch } from 'dva/router'; -import { Spin } from 'antd'; +import { LocaleProvider, Spin } from 'antd'; import dynamic from 'dva/dynamic'; -import { LocalComponent } from './locale/localeContext'; +import { addLocaleData, IntlProvider } from 'react-intl'; import { getRouterData } from './common/router'; import Authorized from './utils/Authorized'; import { getQueryPath } from './utils/utils'; import styles from './index.less'; +import enLocale from './locale/en-US'; +import cnLocale from './locale/zh-CN'; const { ConnectedRouter } = routerRedux; const { AuthorizedRoute } = Authorized; - dynamic.setDefaultLoadingComponent(() => { return ; }); +function getLang() { + return (window.localStorage && localStorage.getItem('locale')) || + (navigator.language || navigator.browserLanguage).toLowerCase() === 'en-us' + ? 'en-US' + : 'zh-CN'; +} + function RouterConfig({ history, app }) { const routerData = getRouterData(app); const UserLayout = routerData['/user'].component; const BasicLayout = routerData['/'].component; - + const appLocale = getLang() === 'zh-CN' ? cnLocale : enLocale; + addLocaleData(appLocale.data); return ( - - - - - } - authority={['admin', 'user']} - redirectPath="/user/login" - /> - - - + + + + + + } + authority={['admin', 'user']} + redirectPath={getQueryPath('/user/login', { + redirect: window.location.href, + })} + /> + + + + ); } -- GitLab