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