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

afc163's avatar
afc163 committed
8 9 10 11 12
import styles from './index.less';

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

function RouterConfig({ history, app }) {
ddcat1115's avatar
ddcat1115 committed
15 16 17
  const routerData = getRouterData(app);
  const UserLayout = routerData['/user'].component;
  const BasicLayout = routerData['/'].component;
18
  return (
afc163's avatar
afc163 committed
19 20
    <LocaleProvider locale={zhCN}>
      <Router history={history}>
ddcat1115's avatar
ddcat1115 committed
21
        <Switch>
ddcat1115's avatar
ddcat1115 committed
22 23
          <Route path="/user" render={props => <UserLayout {...props} />} />
          <Route path="/" render={props => <BasicLayout {...props} />} />
ddcat1115's avatar
ddcat1115 committed
24
        </Switch>
afc163's avatar
afc163 committed
25 26
      </Router>
    </LocaleProvider>
27 28 29 30
  );
}

export default RouterConfig;