我在react中有一个引导导航栏,当屏幕尺寸变小时,它会冷却导航栏并将其更改为汉堡包下拉菜单,但当你点击它时,它不会显示导航项目
这是我的整个导航栏组件:
import * as React from 'react';
import {NavLink, Link} from "react-router-dom";
import "bootstrap/dist/css/bootstrap.css"
export default function Navbar(Props) {
return (
<nav className="navbar navbar-dark bg-dark navbar-expand-sm" style={{marginTop: '-10px'}}>
<Link className="Navbar-brand nav-link text-light col-1 mr-4" to="/">
Logo
</Link>
<div className="row col-10 collapse navbar-collapse navbar-nav " id="navbarNav">
<NavLink className="nav-item nav-link text-light col-2 mr-4 mr-md-1" to="/customers">customers</NavLink>
<NavLink className="nav-item nav-link text-light col-2 mr-4 mr-md-1" to="/rentals">rentals</NavLink>
<NavLink className="nav-item nav-link text-light col-2 mr-4 mr-md-1" to="/movies">movies</NavLink>
</div>
<button className="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span className="navbar-toggler-icon"/>
</button>
<NavLink className="nav-item nav-link text-light col-1 mr-2 mr-md-0 ml-3" to="/login">login</NavLink>
</nav>
);
};
您必须包含jquery和popper.js才能正确地处理下拉列表。如果你还没有安装它们,你可以做如下-
npm install jquery popper.js
现在,您可以将它们包含在Project根目录中的index.js文件或同一文件中。如果你想在整个项目中使用它,那么我建议你将它们包含在index.js文件(src/index.js(中
import 'bootstrap/dist/css/bootstrap.min.css';
import $ from 'jquery';
import Popper from 'popper.js';
import 'bootstrap/dist/js/bootstrap.bundle.min';