router.js 1.18 KB
Newer Older
1
import React from 'react';
2
import { routerRedux, Route, Switch } from 'dva/router';
陈帅's avatar
陈帅 committed
3
import { Spin } from 'antd';
WhatAKitty's avatar
WhatAKitty committed
4
import dynamic from 'dva/dynamic';
陈帅's avatar
陈帅 committed
5
import { LocalComponent } from './locale/localeContext';
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;
陈帅's avatar
陈帅 committed
13

afc163's avatar
afc163 committed
14 15 16
dynamic.setDefaultLoadingComponent(() => {
  return <Spin size="large" className={styles.globalSpin} />;
});
WhatAKitty's avatar
WhatAKitty committed
17 18

function RouterConfig({ history, app }) {
ddcat1115's avatar
ddcat1115 committed
19 20 21
  const routerData = getRouterData(app);
  const UserLayout = routerData['/user'].component;
  const BasicLayout = routerData['/'].component;
陈帅's avatar
陈帅 committed
22

23
  return (
陈帅's avatar
陈帅 committed
24 25 26 27 28 29 30 31 32 33 34 35 36
    <LocalComponent>
      <ConnectedRouter history={history}>
        <Switch>
          <Route path="/user" component={UserLayout} />
          <AuthorizedRoute
            path="/"
            render={props => <BasicLayout {...props} />}
            authority={['admin', 'user']}
            redirectPath="/user/login"
          />
        </Switch>
      </ConnectedRouter>
    </LocalComponent>
37 38 39 40
  );
}

export default RouterConfig;