router.js 1017 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';
afc163's avatar
afc163 committed
6 7 8 9 10
import styles from './index.less';

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

function RouterConfig({ history, app }) {
  const BasicLayout = dynamic({
    app,
WhatAKitty's avatar
WhatAKitty committed
15 16 17
    models: () => [
      import('./models/user'),
    ],
WhatAKitty's avatar
WhatAKitty committed
18 19 20 21 22 23
    component: () => import('./layouts/BasicLayout'),
  });
  const UserLayout = dynamic({
    app,
    component: () => import('./layouts/UserLayout'),
  });
24 25

  return (
afc163's avatar
afc163 committed
26 27
    <LocaleProvider locale={zhCN}>
      <Router history={history}>
ddcat1115's avatar
ddcat1115 committed
28
        <Switch>
WhatAKitty's avatar
WhatAKitty committed
29 30
          <Route path="/user" render={props => <UserLayout {...props} app={app} />} />
          <Route path="/" render={props => <BasicLayout {...props} app={app} />} />
ddcat1115's avatar
ddcat1115 committed
31
        </Switch>
afc163's avatar
afc163 committed
32 33
      </Router>
    </LocaleProvider>
34 35 36 37
  );
}

export default RouterConfig;