#reactjs #navbar #react-bootstrap
Вопрос:
Я пытаюсь скрыть навигационную панель после нажатия на элемент (реакция начальной загрузки 5), но после установки data-bs-toggle="collapse"
и data-bs-target=".navbar-collapse.show"
маршрутизатора реакции не работает.
Я уже заглянул в несколько мест и не могу заставить его работать.
Есть такой код.
import React from 'react';
import "./Navbar.css";
import { Link, NavLink } from 'react-router-dom';
const Navbar = () => {
return (
<nav className="navbar fixed-top navbar navbar-expand-md navbar-dark bg-dark" id="telaprincipal">
<div className="container-fluid">
<NavLink className="navbar-brand" to="/home" activeClassName="active"><i class="fas fa-calculator" ></i></NavLink>
<NavLink className="navbar-brand" to="/home" activeClassName="active">HOME</NavLink>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<NavLink className="nav-link" to="/" activeClassName="active">Home</NavLink>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDarkDropdownMenuLin" role="button"
data-bs-toggle="dropdown" aria-expanded="false">Informações
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDarkDropdownMenuLin">
<li>
<a class="dropdown-item" href="#" id="navbarDarkDropdownMenuLin" role="button"
data-bs-toggle="dropdown">Calculos <i
class="fa fa-caret-right"></i>
</a>
<ul class="submenu dropdown-menu">
<li>
<NavLink data-bs-toggle="collapse" data-bs-target=".navbar-collapse.show" className="dropdown-item" to="/primeiro" activeClassName="active">Cálculo 1</NavLink>
</li>
<li>
<NavLink data-bs-toggle="collapse" data-bs-target=".navbar-collapse.show" className="dropdown-item" to="/segundo" activeClassName="active">Cálculo 2</NavLink>
</li>
<li>
<NavLink data-bs-toggle="collapse" data-bs-target=".navbar-collapse.show" className="dropdown-item" to="/terceiro" activeClassName="active">Cálculo 3</NavLink>
</li>
<li>
<NavLink data-bs-toggle="collapse" data-bs-target=".navbar-collapse.show" className="dropdown-item" to="/quarto" activeClassName="active">Cálculo 4</NavLink>
</li>
<li>
<NavLink data-bs-toggle="collapse" data-bs-target=".navbar-collapse.show" className="dropdown-item" to="/quinto" activeClassName="active">Cálculo 5</NavLink>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item">
<NavLink className="nav-link" to="/conversor" activeClassName="active">Conversor de Unidades</NavLink>
</li>
<li class="nav-item">
<NavLink className="nav-link" to="/fale" activeClassName="active">Fale conosco</NavLink>
</li>
</ul>
<form class="d-flex">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search"/>
<button class="btn btn-outline-primary" type="submit">Search</button>
</form>
</div>
</div>
</nav>