router.js 1.25 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';
ddcat1115's avatar
ddcat1115 committed
5
import { getRouterData } from './common/router';
ddcat1115's avatar
ddcat1115 committed
6
import Authorized from './utils/Authorized';
7
import { getQueryPath } from './utils/utils';
陈帅's avatar
陈帅 committed
8
import { LocalComponent } from './locale/localeContext';
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;
afc163's avatar
afc163 committed
13 14 15
dynamic.setDefaultLoadingComponent(() => {
  return <Spin size="large" className={styles.globalSpin} />;
});
WhatAKitty's avatar
WhatAKitty committed
16 17

function RouterConfig({ history, app }) {
ddcat1115's avatar
ddcat1115 committed
18 19 20
  const routerData = getRouterData(app);
  const UserLayout = routerData['/user'].component;
  const BasicLayout = routerData['/'].component;
21
  return (
陈帅's avatar
陈帅 committed
22 23 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={getQueryPath('/user/login', {
              redirect: window.location.href,
            })}
          />
        </Switch>
      </ConnectedRouter>
    </LocalComponent>
37 38 39 40
  );
}

export default RouterConfig;