router.js 1.27 KB
Newer Older
1
import React from 'react';
2
import { routerRedux, 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>
ddcat1115's avatar
ddcat1115 committed
24 25 26 27 28 29 30 31 32 33 34 35
          <AuthorizedRoute
            path="/user"
            render={props => <UserLayout {...props} />}
            authority="guest"
            redirectPath="/"
          />
          <AuthorizedRoute
            path="/"
            render={props => <BasicLayout {...props} />}
            authority={['admin', 'user']}
            redirectPath="/user/login"
          />
ddcat1115's avatar
ddcat1115 committed
36
        </Switch>
37
      </ConnectedRouter>
afc163's avatar
afc163 committed
38
    </LocaleProvider>
39 40 41 42
  );
}

export default RouterConfig;