router.js 1.19 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>
24
          <Route
ddcat1115's avatar
ddcat1115 committed
25
            path="/user"
26
            component={UserLayout}
ddcat1115's avatar
ddcat1115 committed
27 28 29 30 31 32 33
          />
          <AuthorizedRoute
            path="/"
            render={props => <BasicLayout {...props} />}
            authority={['admin', 'user']}
            redirectPath="/user/login"
          />
ddcat1115's avatar
ddcat1115 committed
34
        </Switch>
35
      </ConnectedRouter>
afc163's avatar
afc163 committed
36
    </LocaleProvider>
37 38 39 40
  );
}

export default RouterConfig;