Commit 81774c23 authored by ι™ˆεΈ…'s avatar ι™ˆεΈ…

rebase: rebase v2

parent f07927f8
import React from 'react'; import React from 'react';
import { routerRedux, Route, Switch } from 'dva/router'; import { routerRedux, Route, Switch } from 'dva/router';
import { Spin } from 'antd'; import { LocaleProvider, Spin } from 'antd';
import dynamic from 'dva/dynamic'; import dynamic from 'dva/dynamic';
import { LocalComponent } from './locale/localeContext'; import { addLocaleData, IntlProvider } from 'react-intl';
import { getRouterData } from './common/router'; import { getRouterData } from './common/router';
import Authorized from './utils/Authorized'; import Authorized from './utils/Authorized';
import { getQueryPath } from './utils/utils'; import { getQueryPath } from './utils/utils';
import styles from './index.less'; import styles from './index.less';
import enLocale from './locale/en-US';
import cnLocale from './locale/zh-CN';
const { ConnectedRouter } = routerRedux; const { ConnectedRouter } = routerRedux;
const { AuthorizedRoute } = Authorized; const { AuthorizedRoute } = Authorized;
dynamic.setDefaultLoadingComponent(() => { dynamic.setDefaultLoadingComponent(() => {
return <Spin size="large" className={styles.globalSpin} />; return <Spin size="large" className={styles.globalSpin} />;
}); });
function getLang() {
return (window.localStorage && localStorage.getItem('locale')) ||
(navigator.language || navigator.browserLanguage).toLowerCase() === 'en-us'
? 'en-US'
: 'zh-CN';
}
function RouterConfig({ history, app }) { function RouterConfig({ history, app }) {
const routerData = getRouterData(app); const routerData = getRouterData(app);
const UserLayout = routerData['/user'].component; const UserLayout = routerData['/user'].component;
const BasicLayout = routerData['/'].component; const BasicLayout = routerData['/'].component;
const appLocale = getLang() === 'zh-CN' ? cnLocale : enLocale;
addLocaleData(appLocale.data);
return ( return (
<LocalComponent> <IntlProvider locale={appLocale.locale} messages={appLocale.messages}>
<LocaleProvider locale={appLocale.antd}>
<ConnectedRouter history={history}> <ConnectedRouter history={history}>
<Switch> <Switch>
<Route path="/user" component={UserLayout} /> <Route path="/user" component={UserLayout} />
...@@ -29,11 +39,14 @@ function RouterConfig({ history, app }) { ...@@ -29,11 +39,14 @@ function RouterConfig({ history, app }) {
path="/" path="/"
render={props => <BasicLayout {...props} />} render={props => <BasicLayout {...props} />}
authority={['admin', 'user']} authority={['admin', 'user']}
redirectPath="/user/login" redirectPath={getQueryPath('/user/login', {
redirect: window.location.href,
})}
/> />
</Switch> </Switch>
</ConnectedRouter> </ConnectedRouter>
</LocalComponent> </LocaleProvider>
</IntlProvider>
); );
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment