router.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import React from 'react';
  2. import { routerRedux, Route, Switch } from 'dva/router';
  3. import { LocaleProvider, Spin } from 'antd';
  4. import zhCN from 'antd/lib/locale-provider/zh_CN';
  5. import dynamic from 'dva/dynamic';
  6. import { getRouterData } from './common/router';
  7. import Authorized from './utils/Authorized';
  8. import styles from './index.less';
  9. const { ConnectedRouter } = routerRedux;
  10. const { AuthorizedRoute } = Authorized;
  11. dynamic.setDefaultLoadingComponent(() => {
  12. return <Spin size="large" className={styles.globalSpin} />;
  13. });
  14. function RouterConfig({ history, app }) {
  15. const routerData = getRouterData(app);
  16. const UserLayout = routerData['/user'].component;
  17. const BasicLayout = routerData['/'].component;
  18. return (
  19. <LocaleProvider locale={zhCN}>
  20. <ConnectedRouter history={history}>
  21. <Switch>
  22. <Route
  23. path="/user"
  24. component={UserLayout}
  25. />
  26. <AuthorizedRoute
  27. path="/"
  28. render={props => <BasicLayout {...props} />}
  29. authority={['admin', 'platform']}
  30. redirectPath="/user/login"
  31. />
  32. </Switch>
  33. </ConnectedRouter>
  34. </LocaleProvider>
  35. );
  36. }
  37. export default RouterConfig;