antd 主页地址:https://ant.design/docs/react/introduce

在使用过程中,不能照搬antd的组件代码,因为有些并不合适。首先,菜单并没有做跳转功能,仅仅是菜单,需要在它的基础方法中添加我们的业务代码。

/*菜单组件,所有的方法都要bind this*/

import React,{Component} from 'react';
import {render} from 'react-dom';
import {Link,browserHistory} from 'react-router'; import Menu from 'antd/lib/menu';
import Icon from 'antd/lib/icon';
const SubMenu = Menu.SubMenu;
const MenuItemGroup = Menu.ItemGroup; import {user_search_path,
application_search_path,navigation_search,advertising_search} from 'config'; export default class Sidebar extends Component{
constructor(props){
super(props);
this.state = {
current: '1',
openKeys: []
}
} handleClick(e) {
/*这里要做判断,判断是点击哪个菜单,就跳转到相应的菜单内容,使用router进行跳转*/
if(e.key == "1"){
browserHistory.push(user_search_path);
}else if(e.key == '2'){
browserHistory.push(application_search_path);
}else if(e.key == '3'){
browserHistory.push(navigation_search);
}else if(e.key == '4'){
browserHistory.push(advertising_search);
} this.setState({
current: e.key,
openKeys: e.keyPath.slice(1)
});
} onToggle(info) {
console.log('onToggle', info);
this.setState({
openKeys: info.open ? info.keyPath : info.keyPath.slice(1)
});
} getKeyPath(key) {
const map = {
sub1: ['sub1'],
sub2: ['sub2'],
sub3: ['sub2', 'sub3'],
sub4: ['sub4'],
};
return map[key] || [];
} render(){ return(
<div>
<Menu
mode="inline"
openKeys={this.state.openKeys}
selectedKeys={[this.state.current]}
style={{ width: 230 }}
onOpen = {this.onToggle.bind(this)} /*打开菜单*/
onClose = {this.onToggle.bind(this)} /*关闭菜单*/
onClick={this.handleClick.bind(this)} /*触发菜单*/
>
<SubMenu key="sub1" title={<span><Icon type="user" /><span>用户服务</span></span>}>
<Menu.Item key="1">设置权限</Menu.Item>
</SubMenu>
<SubMenu key="sub2" title={<span><Icon type="setting" /><span>配置服务</span></span>}>
<Menu.Item key="2">app版本查询</Menu.Item>
<SubMenu key="sub3" title="app配置版本查询">
<Menu.Item key="3">导航配置查询</Menu.Item>
<Menu.Item key="4">广告配置查询</Menu.Item>
</SubMenu>
<Menu.Item key="5">app changeLog</Menu.Item>
</SubMenu>
<SubMenu key="sub4" title={<span><Icon type="mail" /><span>短信服务</span></span>}>
</SubMenu>
</Menu>
</div>
);
}
}

第二步,通过页面加载组件Parent.js,固定菜单与菜单内容的位置

import React,{Component} from 'react';
import {render} from 'react-dom';
import Icon from 'antd/lib/icon'; import jiChu from '../../../build/images/jichu.png'; import HeaderRight from '../login/HeaderRight.js';
import SearchUser from '../login/SearchUser.js';
import Sidebar from '../sidebar/Sidebar.js'; import style from '../../../build/css/login.css'; export default class Parent extends Component{
constructor(props){
super(props);
} render(){ const headerUserPanel = (<HeaderRight {...this.props} />);
const search = (<SearchUser {...this.props} />);
const sidebars = (<Sidebar {...this.props} />); /*菜单组件*/ return(
<div className="main-view">
<div className="main-sidebar">
<div className="sidebar-wrapper">
<div className="sidebar">
<div className="logo">
<img src={jiChu} className="logoPic" />
</div>
<div className="sidebar-nav">
{sidebars}
</div>
<div className="sidebar-footer">
<span><Icon type="double-left" /><span>收缩菜单</span></span>
</div>
</div>
</div>
</div>
<div className="main-wrapper">
<div className="main-nav-bar">
<div className="navbar">
{headerUserPanel}
</div>
<div className="main-body">
<div className="main-content">
{this.props.children} /*菜单组件对应内容*/
</div>
</div>
</div>
</div>
</div> );
}
}

最后一步,在路由中通过path将页面与路径关联,这样我们在菜单组件中的跳转就是通过这一步控制

import React from 'react';
import {render} from 'react-dom';
import { Router , Redirect, Route , IndexRoute , browserHistory } from 'react-router';
import { Provider } from 'react-redux' const store = configureStore();
render((
<Provider store={store}>
<Router history={browserHistory}>
<Route path={user_service_path} component={Parent}> <Route path={user_sidebar_bath} component={Sidebar}></Route> <Route path={application_search_path} component={AdvertisementTablePannelContainer}></Route> </Provider>
), document.getElementById('root'));

完毕!

使用antd UI 制作菜单的更多相关文章

  1. [UI]抽屉菜单DrawerLayout分析(一)

    本文转载于:http://www.cnblogs.com/avenwu/archive/2014/04/16/3669367.html 侧拉菜单作为常见的导航交互控件,最开始在没有没有android官 ...

  2. Adobe Edge Animate –使用css制作菜单

    Adobe Edge Animate –使用css制作菜单 版权声明: 本文版权属于 北京联友天下科技发展有限公司. 转载的时候请注明版权和原文地址. 效果图:

  3. [UI]抽屉菜单DrawerLayout分析(三)

    在[UI]抽屉菜单DrawerLayout分析(一)和[UI]抽屉菜单DrawerLayout分析(二)中分别介绍了DrawerLayout得基本框架结构和ViewDragerHelper的作用以及手 ...

  4. Jquery.Treeview+Jquery UI制作Web文件预览

    效果图: 前台Html: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="D ...

  5. React 版 V2EX 社区( react & react-router & axios & antd ui)

    目录 项目简介 在线演示 截图演示 踩坑 项目简介(1/4) Github: https://github.com/bergwhite/v2ex-react 项目使用React.Reac-router ...

  6. Flutter实战视频-移动电商-55.购物车_底部结算栏UI制作

    55.购物车_底部结算栏UI制作 主要做下面结算这一栏目 cart_bottom.dart页面 先设置下内边距 拆分成三个子元素 全选 因为有一个文本框和一个全选的text文本,所以这里也用了Row布 ...

  7. WPF利用radiobutton制作菜单按钮

    原文:WPF利用radiobutton制作菜单按钮 版权声明:欢迎转载.转载请注明出处,谢谢 https://blog.csdn.net/wzcool273509239/article/details ...

  8. 学习CSS制作菜单列表,举一反三

    1.普通的二三级菜单 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type&qu ...

  9. 使用antd UI组件有感

    公司使用的的react.js的版本提14.7的,JS版本使用的是ES6语法,因此在使用antd过程中,有些许不愉快的记录,分享给大家,一起学习: 如果是react 14.7版本时,使用getField ...

随机推荐

  1. 数组Array,集合List与字符串String,整形int的get类方法。

    比如 public static List<DownCountCmd> getDownCountCmdList() { return downCount; } List<DownCo ...

  2. Android 监听ScrollView的滑动

    我们需要监听ScroView的滑动情况,比如滑动了多少距离,是否滑到布局的顶部或者底部.可惜的是SDK并没有相应的方法,不过倒是提供了一个 protected void onScrollChanged ...

  3. [分享] 很多人手机掉了,却不知道怎么找回来。LZ亲身经历讲述手机找回过程,申请加精!

    文章开头:(LZ文笔不好,以下全部是文字描述,懒得配图.因为有人说手机掉了,他们问我是怎么找回来的.所以想写这篇帖子.只不过前段时间忙,没时间.凑端午节给大家一些经验) 还是先谢谢被偷经历吧!5月22 ...

  4. Mac入门教程之: Command键5个隐藏功能

    Mac 电脑的 Command 键位于空格边上,是 OS X 系统很多快捷键组合的一部分.不过,Command 自己也能完成很多操作,帮助用户更好的在 OS X 中完成各项任务,下面是 Command ...

  5. JVM之ParNew收集器

    新生代收集器,CMS默认搭配,Serial的多线程版本. -XX:UseParNewGC:指定使用ParNew收集器. -XX:ParalletGCThreads:指定限制垃圾收收集的线程数量. 默认 ...

  6. 从AdventureWorks学习数据库建模——保留历史数据

    在业务需求中,经常需要我们在系统中能够记录历史信息,能够查看到历史变动情况,这时我们可以通过增加开始结束时间字段来记录数据的历史版本.对数据的历史记录主要分为:关系.属性历史,实体历史和变更历史. 关 ...

  7. 为什么 MySQL 回滚事务也会导致 ibd 文件增大?

    一个简单的测试: start transaction; insert into tb1 values(3, repeat('a', 65000),'x',1); --commit; rollback; ...

  8. 【转】jquery 中scrollTop在Firefox下不起作用

    原文链接:http://stackoverflow.com/questions/8149155/animate-scrolltop-not-working-in-firefox Animate scr ...

  9. Ubuntu nginx 配置404错误页面

    1.创建自己的404.html页面: 2.更改nginx.conf在http定义区域加入: /etc/nginx# vim nginx.conf 下添加 fastcgi_intercept_error ...

  10. Redis3 本地安装集群的记录

    引用CSDN文章 环境 centos6.7 目标 redis 三主三从的集群 step 1 编译,如果出错,则根据提示安装依赖 tar -zxvf redis-3.0.0.tar.gz mv redi ...