router.js 1.21 KB
Newer Older
1
import React from 'react';
ddcat1115's avatar
ddcat1115 committed
2
import { Router, 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';

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

function RouterConfig({ history, app }) {
ddcat1115's avatar
ddcat1115 committed
16 17 18
  const routerData = getRouterData(app);
  const UserLayout = routerData['/user'].component;
  const BasicLayout = routerData['/'].component;
19
  return (
afc163's avatar
afc163 committed
20 21
    <LocaleProvider locale={zhCN}>
      <Router history={history}>
ddcat1115's avatar
ddcat1115 committed
22
        <Switch>
ddcat1115's avatar
ddcat1115 committed
23 24 25 26 27 28 29 30 31 32 33 34
          <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
35
        </Switch>
afc163's avatar
afc163 committed
36 37
      </Router>
    </LocaleProvider>
38 39 40 41
  );
}

export default RouterConfig;