router.js 1.28 KB
Newer Older
1
import React from 'react';
2
import { routerRedux, Route, Switch } from 'dva/router';
afc163's avatar
afc163 committed
3
import { LocaleProvider, Spin } from 'antd';
afc163's avatar
afc163 committed
4
import zhCN from 'antd/lib/locale-provider/zh_CN';
WhatAKitty's avatar
WhatAKitty committed
5
import dynamic from 'dva/dynamic';
ddcat1115's avatar
ddcat1115 committed
6
import { getRouterData } from './common/router';
ddcat1115's avatar
ddcat1115 committed
7
import Authorized from './utils/Authorized';
8
import { getQueryPath } from './utils/utils';
afc163's avatar
afc163 committed
9 10
import styles from './index.less';

11
const { ConnectedRouter } = routerRedux;
ddcat1115's avatar
ddcat1115 committed
12
const { AuthorizedRoute } = Authorized;
afc163's avatar
afc163 committed
13 14 15
dynamic.setDefaultLoadingComponent(() => {
  return <Spin size="large" className={styles.globalSpin} />;
});
WhatAKitty's avatar
WhatAKitty committed
16 17

function RouterConfig({ history, app }) {
ddcat1115's avatar
ddcat1115 committed
18 19 20
  const routerData = getRouterData(app);
  const UserLayout = routerData['/user'].component;
  const BasicLayout = routerData['/'].component;
21
  return (
afc163's avatar
afc163 committed
22
    <LocaleProvider locale={zhCN}>
23
      <ConnectedRouter history={history}>
ddcat1115's avatar
ddcat1115 committed
24
        <Switch>
jim's avatar
jim committed
25
          <Route path="/user" component={UserLayout} />
ddcat1115's avatar
ddcat1115 committed
26 27 28 29
          <AuthorizedRoute
            path="/"
            render={props => <BasicLayout {...props} />}
            authority={['admin', 'user']}
30 31 32
            redirectPath={getQueryPath('/user/login', {
              redirect: window.location.href,
            })}
ddcat1115's avatar
ddcat1115 committed
33
          />
ddcat1115's avatar
ddcat1115 committed
34
        </Switch>
35
      </ConnectedRouter>
afc163's avatar
afc163 committed
36
    </LocaleProvider>
37 38 39 40
  );
}

export default RouterConfig;