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

LoginTab.js 672B

123456789101112131415161718192021222324252627282930313233
  1. import React, { Component } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { Tabs } from 'antd';
  4. const { TabPane } = Tabs;
  5. const generateId = (() => {
  6. let i = 0;
  7. return (prefix = '') => {
  8. i += 1;
  9. return `${prefix}${i}`;
  10. };
  11. })();
  12. export default class LoginTab extends Component {
  13. static __ANT_PRO_LOGIN_TAB = true;
  14. static contextTypes = {
  15. tabUtil: PropTypes.object,
  16. };
  17. constructor(props) {
  18. super(props);
  19. this.uniqueId = generateId('login-tab-');
  20. }
  21. componentWillMount() {
  22. if (this.context.tabUtil) {
  23. this.context.tabUtil.addTab(this.uniqueId);
  24. }
  25. }
  26. render() {
  27. return <TabPane {...this.props} />;
  28. }
  29. }