简体   繁体   English

如何在React Router中使用react-burger-menu?

[英]How to use react-burger-menu with react router?

I'm trying to follow this guide ( https://github.com/negomi/react-burger-menu ) to implement react-burger-menu with react-router 我正在尝试遵循本指南( https://github.com/negomi/react-burger-menu )来使用react-router实现react-burger-menu

Specifically this part https://github.com/negomi/react-burger-menu/wiki/FAQ#why-doesnt-the-link-component-from-react-router-work . 具体来说,这部分https://github.com/negomi/react-burger-menu/wiki/FAQ#why-doesnt-the-link-component-from-react-router-work

The issue I'm having is that the menu button seems to be placed on the left of the menu and the menu does not seem to hide. 我遇到的问题是菜单按钮似乎位于菜单的左侧,并且菜单似乎没有隐藏。 Here's a screenshot of what that looks like. 这是看起来的屏幕截图。

在此处输入图片说明

My code looks like this: 我的代码如下所示:

app.js app.js

// This component handles the App template used on every page.
import React, {PropTypes} from 'react';
import SideBar from './common/Header';

class App extends React.Component {
    render() {
        return (
            <div className="container-fluid">
                        <SideBar />
                        {this.props.children}
            </div>
        );
    }
}

App.propTypes = {
    children: PropTypes.object.isRequired
};

export default App;

header.js header.js

import React, {PropTypes} from 'react';
import { Link, IndexLink } from 'react-router';
import {slide as Menu} from 'react-burger-menu';
import Radium from 'radium';

let RadiumLink = Radium(Link);
let RadiumIndexLink = Radium(IndexLink);

const SideBar = () => {
    return (


    <Menu className="bm-menu">
        <RadiumIndexLink className="bm-item-list" to="/" activeClassName="active">Home</RadiumIndexLink>
        <RadiumLink className="bm-item-list" to="/courses" activeClassName="active">Courses</RadiumLink>
        <RadiumLink className="bm-item-list" to="/about" activeClassName="active">About</RadiumLink>
    </Menu>

    );
};

export default SideBar;

style.css style.css文件

#app {
    font: 14px 'Helvetica Neue', Helvetica, Arial, sans-serif;
    color: #4d4d4d;
    min-width: 550px;
    max-width: 850px;
    margin: 0 auto;
}

a.active {
    color: orange;
}

nav {
    padding-top: 20px;
    padding-bottom: 20px;
}

/* Position and sizing of burger button */
.bm-burger-button {
  position: fixed;
  width: 36px;
  height: 30px;
  left: 36px;
  top: 36px;
}

/* Color/shape of burger icon bars */
.bm-burger-bars {
  background: #373a47;
}

/* Position and sizing of clickable cross button */
.bm-cross-button {
  height: 24px;
  width: 24px;
}

/* Color/shape of close button cross */
.bm-cross {
  background: #bdc3c7;
}

/* General sidebar styles */
.bm-menu {
  background: #373a47;
  padding: 2.5em 1.5em 0;
  font-size: 1.15em;
}

/* Morph shape necessary with bubble or elastic */
.bm-morph-shape {
  fill: #373a47;
}

/* Wrapper for item list */
.bm-item-list {
  color: #b8b7ad;
  padding: 0.8em;
}

/* Styling of overlay */
.bm-overlay {
  background: rgba(0, 0, 0, 0.3);
}

Why is the button for the toggle appearing to the left of the actual menu and why doesn't the actual menu hide? 为什么切换按钮显示在实际菜单的左侧,为什么不隐藏实际菜单? If I click the toggle, the menu just shifts right even more... 如果单击切换开关,菜单将向右移动更多...

Add this to your CSS: 将此添加到您的CSS:

.bm-menu-wrap {
  bottom: 0;
  left: 0;
}

This will position the menu to the left of the screen. 这会将菜单置于屏幕左侧。

The button appearing on the left side of the screen is intentional, if you want it to stick to the page instead of following you when you scroll, change 屏幕左侧出现的按钮是有意的,如果您希望它停留在页面上而不是滚动时跟随您,请更改

.bm-burger-button {
   position:fixed;
} 

to

.bm-burger-button {
   position:absolute;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM