reactjs - Reactstrap Bootstrap Navbar在React应用中不起作用

标签 reactjs bootstrap-4 navbar create-react-app reactstrap

我用“创建react-app”创建了一个react应用。

我现在正在尝试从Reactstrap添加导航栏。我从Reactstrap复制粘贴(我将其添加为一个react组件)website:

import React from 'react';
import {
  Collapse,
  Navbar,
  NavbarToggler,
  NavbarBrand,
  Nav,
  NavItem,
  NavLink,
  UncontrolledDropdown,
  DropdownToggle,
  DropdownMenu,
  DropdownItem } from 'reactstrap';

export default class Example extends React.Component {
  constructor(props) {
    super(props);

    this.toggle = this.toggle.bind(this);
    this.state = {
      isOpen: false
    };
  }
  toggle() {
    this.setState({
      isOpen: !this.state.isOpen
    });
  }
  render() {
    return (
      <div>
        <Navbar color="light" light expand="md">
          <NavbarBrand href="/">reactstrap</NavbarBrand>
          <NavbarToggler onClick={this.toggle} />
          <Collapse isOpen={this.state.isOpen} navbar>
            <Nav className="ml-auto" navbar>
              <NavItem>
                <NavLink href="/components/">Components</NavLink>
              </NavItem>
              <NavItem>
                <NavLink href="https://github.com/reactstrap/reactstrap">GitHub</NavLink>
              </NavItem>
              <UncontrolledDropdown nav inNavbar>
                <DropdownToggle nav caret>
                  Options
                </DropdownToggle>
                <DropdownMenu right>
                  <DropdownItem>
                    Option 1
                  </DropdownItem>
                  <DropdownItem>
                    Option 2
                  </DropdownItem>
                  <DropdownItem divider />
                  <DropdownItem>
                    Reset
                  </DropdownItem>
                </DropdownMenu>
              </UncontrolledDropdown>
            </Nav>
          </Collapse>
        </Navbar>
      </div>
    );
  }
}

并且它不起作用。我在我的应用程序中得到了这个:

navbar in react app

之前我在Bootstrap,React和Navbar上也遇到过类似的问题,但我真的很惊讶它在Reactstrap中正在发生。
你知道为什么会这样吗?

最佳答案

您还需要引导,并使用react:

npm install --save bootstrap
npm install --save reactstrap react react-dom
import 'bootstrap/dist/css/bootstrap.css';
import { Button } from 'reactstrap'; 

关于reactjs - Reactstrap Bootstrap Navbar在React应用中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54520376/

相关文章:

node.js - Azure 网站上的 React 应用程序的 Http 404

html - 在台式计算机上尝试匹配引导卡高度

html - Bootstrap 4 列和行产生不需要的填充

HTML/CSS 导航栏下拉列表不以列表格式显示

html - 水平导航栏中心,但链接是垂直的?

javascript - 如何使用 Material UI 网格组件将一个项目左对齐,另一项右对齐

javascript - 使用 "Tinder"+ "Firebase"构建 "Geofire"应用程序,这可能吗?

javascript - 如何将上下文传播到路由器组件。 react 堆

css - 如何从复选框中删除蓝色边框(bootstrap 4.1)

css - Bootstrap Navbar 品牌在左侧,链接居中