1 | import React from 'react';
|
2 | import { Layout, Menu, Icon } from 'antd';
|
3 | import {
|
4 | BrowserRouter as Router,
|
5 | Route,
|
6 | HashRouter,
|
7 | histroy,
|
8 | Redirect,
|
9 | Link
|
10 | } from 'react-router-dom';
|
11 |
|
12 | const { SubMenu } = Menu;
|
13 | const { Sider } = Layout;
|
14 |
|
15 | export default class SiderView extends React.Component {
|
16 |
|
17 | constructor(props) {
|
18 | super(props);
|
19 | }
|
20 |
|
21 | $renderItem(db) {
|
22 |
|
23 | const{md, config} = db;
|
24 |
|
25 | const res = [];
|
26 |
|
27 | const category = config.category.slice();
|
28 |
|
29 |
|
30 | const renderMenuItem = (list, cg) => {
|
31 | const items = list.map((item, i) => {
|
32 | const to = `/page/${item.page}`;
|
33 | return(
|
34 | <Menu.Item key={item.page}>
|
35 | <Link to={to}>
|
36 | {item.page}
|
37 | </Link>
|
38 | </Menu.Item>
|
39 | )
|
40 | });
|
41 |
|
42 | return items;
|
43 | };
|
44 |
|
45 |
|
46 | if (md.default && md.default.length) {
|
47 | res.push(renderMenuItem(md.default));
|
48 | }
|
49 |
|
50 | category.forEach((cg, i) => {
|
51 | const list = md[cg];
|
52 | const items = renderMenuItem(list, cg);
|
53 |
|
54 | res.push((
|
55 | <SubMenu key={cg + '-key'} title={cg}>
|
56 | {items}
|
57 | </SubMenu>
|
58 | ));
|
59 | });
|
60 |
|
61 | return res;
|
62 | }
|
63 |
|
64 | componentDidMount() {
|
65 |
|
66 |
|
67 |
|
68 | console.log(1111)
|
69 | console.log(histroy);
|
70 | }
|
71 |
|
72 | render() {
|
73 | const menuItems = this.$renderItem(this.props.db);
|
74 | const{md, config} =this.props.db;
|
75 | const cg = config.category[0];
|
76 |
|
77 | const defaultKeys = config.category.map(item => {
|
78 | return item + '-key';
|
79 | })
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | console.log(window.history);
|
85 |
|
86 | window.history.pushState({
|
87 | foo: "bar"
|
88 | }, "page 2")
|
89 |
|
90 | return (
|
91 | <Menu
|
92 | mode="inline"
|
93 | defaultSelectedKeys={['0']}
|
94 | defaultOpenKeys={defaultKeys}
|
95 | style={{ height: '100%' }}
|
96 | >
|
97 | {menuItems}
|
98 | </Menu>
|
99 | )
|
100 | }
|
101 | } |
\ | No newline at end of file |