UNPKG

2.41 kBJavaScriptView Raw
1import React from 'react';
2import { Layout, Menu, Icon } from 'antd';
3import {
4 BrowserRouter as Router,
5 Route,
6 HashRouter,
7 Histroy,
8 Redirect,
9 Link
10} from 'react-router-dom';
11
12const { SubMenu } = Menu;
13const { Sider } = Layout;
14
15export 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 // 如果md 文件没有设置 category 直接渲染 menuItem;
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 // const{md, config} =this.props.db;
66 // const cg = config.category[0];
67 // if(cg) PubSub.publish('SET_PAGE', md[cg][0].page);
68
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 // <Redirect to={`/page/${md[cg][0].page}`}/>
82
83 // window.location('/page/B')
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