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}>
<ConnectedRouter history={history}> <LocaleProvider locale={appLocale.antd}>
<Switch> <ConnectedRouter history={history}>
<Route path="/user" component={UserLayout} /> <Switch>
<AuthorizedRoute <Route path="/user" component={UserLayout} />
path="/" <AuthorizedRoute
render={props => <BasicLayout {...props} />} path="/"
authority={['admin', 'user']} render={props => <BasicLayout {...props} />}
redirectPath="/user/login" authority={['admin', 'user']}
/> redirectPath={getQueryPath('/user/login', {
</Switch> redirect: window.location.href,
</ConnectedRouter> })}
</LocalComponent> />
</Switch>
</ConnectedRouter>
</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