UNPKG

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