gpt4 book ai didi

javascript - React bootstrap 导航栏折叠不起作用

转载 作者:行者123 更新时间:2023-12-03 13:39:49 25 4
gpt4 key购买 nike

我使用了 React Bootstrap 导航栏,还使用了 react-scroll 来实现流畅的导航。它工作正常,但在响应模式下单击任何导航项时导航栏不会折叠。

套餐

import React, { Component } from "react";
import { NavLink } from "react-router-dom";
import { Link } from "react-scroll";
import { LinkContainer } from "react-router-bootstrap";
import { Navbar, Container, NavDropdown, Nav, Dropdown } from "react-bootstrap";

导航栏

<Navbar
sticky="top"
id="navbar"
bg="light"
expand="lg"
className="navbar navbar-expand-lg navbar-light bg-light"
collapseOnSelect={true}
>
<Navbar.Toggle aria-controls="basic-navbar-nav" />
<Navbar.Collapse id="basic-navbar-nav">
<Nav className="ml-auto">
<Link
activeClass="active"
to="features"
spy={true}
smooth={true}
offset={-70}
duration={800}
className="nav-link"
onClick={this.closeNavbar}
>
Features
</Link>

<Link
activeClass="active"
to="about"
spy={true}
smooth={true}
offset={-70}
duration={800}
className="nav-link"
>
About
</Link>
</Nav>
</Navbar.Collapse>
</Navbar>

最佳答案

有同样的问题。我发现如果我们为 Nav.Link 项目添加“eventKey”,“collapseOnSelect”就会起作用

示例:

import { Link } from 'react-router-dom';
import { Nav, Navbar} from 'react-bootstrap';

<Navbar collapseOnSelect expand="lg">
<Navbar.Toggle />
<Navbar.Collapse>
<Nav className="mr-auto d-block">
<Nav.Item>
<Nav.Link eventKey="1" as={Link} to="/Home">
Home
</Nav.Link>
</Nav.Item>
<Nav.Item>
<Nav.Link eventKey="2" as={Link} to="/Contant">
Page Contant
</Nav.Link>
</Nav.Item>
</Nav>
</Navbar.Collapse>
</Navbar>

关于javascript - React bootstrap 导航栏折叠不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54859515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com