动态菜单和动态路由的 antd pro

UserLayout.js 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import React, { Fragment } from 'react';
  2. import { Link, Redirect, Switch, Route } from 'dva/router';
  3. import DocumentTitle from 'react-document-title';
  4. import { Icon } from 'antd';
  5. import GlobalFooter from '../components/GlobalFooter';
  6. import styles from './UserLayout.less';
  7. import logo from '../assets/logo.svg';
  8. import { getRoutes } from '../utils/utils';
  9. const links = [
  10. {
  11. key: 'help',
  12. title: '帮助',
  13. href: '',
  14. },
  15. {
  16. key: 'privacy',
  17. title: '隐私',
  18. href: '',
  19. },
  20. {
  21. key: 'terms',
  22. title: '条款',
  23. href: '',
  24. },
  25. ];
  26. const copyright = (
  27. <Fragment>
  28. Copyright <Icon type="copyright" /> 2018 蚂蚁金服体验技术部出品
  29. </Fragment>
  30. );
  31. class UserLayout extends React.PureComponent {
  32. getPageTitle() {
  33. const { routerData, location } = this.props;
  34. const { pathname } = location;
  35. let title = 'Ant Design Pro';
  36. if (routerData[pathname] && routerData[pathname].name) {
  37. title = `${routerData[pathname].name} - Ant Design Pro`;
  38. }
  39. return title;
  40. }
  41. render() {
  42. const { routerData, match } = this.props;
  43. return (
  44. <DocumentTitle title={this.getPageTitle()}>
  45. <div className={styles.container}>
  46. <div className={styles.content}>
  47. <div className={styles.top}>
  48. <div className={styles.header}>
  49. <Link to="/">
  50. <img alt="logo" className={styles.logo} src={logo} />
  51. <span className={styles.title}>Ant Design</span>
  52. </Link>
  53. </div>
  54. <div className={styles.desc}>Ant Design 是西湖区最具影响力的 Web 设计规范</div>
  55. </div>
  56. <Switch>
  57. {getRoutes(match.path, routerData).map(item => (
  58. <Route
  59. key={item.key}
  60. path={item.path}
  61. component={item.component}
  62. exact={item.exact}
  63. />
  64. ))}
  65. <Redirect exact from="/user" to="/user/login" />
  66. </Switch>
  67. </div>
  68. <GlobalFooter links={links} copyright={copyright} />
  69. </div>
  70. </DocumentTitle>
  71. );
  72. }
  73. }
  74. export default UserLayout;