router.js 1.15 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';
afc163's avatar
afc163 committed
8 9
import styles from './index.less';

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

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

export default RouterConfig;