0

Here I am facing a strange issue after calling a modal form, the navbar dropdowns stop working.

Any clue?

here is the link to my code: https://codesandbox.io/s/great-stonebraker-hfcln?fontsize=14&hidenavigation=1&theme=dark

To reproduce the issue: from Navbar go to Master data > customers > the modal form will open > close the modal form > then go back to the menu and they to open the master data drop down.

HichemSeeSharp
  • 3,240
  • 2
  • 22
  • 44

2 Answers2

0

Use react router's Link to navigate:

import { Link } from "react-router-dom";

In MainNav component:

<Link to="/customers">
  <NavDropdown.Item >Customers</NavDropdown.Item>
</Link>

https://codesandbox.io/s/eloquent-bash-tkhn8?file=/src/mainnav.jsx

Href redirects the page to a particular location(Page redirects, state of the app is lost). Link from react-router-dom allows you to navigate to different routes with the page loading retaining state of your react app (internal routing).

Ashwin R
  • 744
  • 7
  • 14
0

I found the solution,
Basically we need to convert the Navbar.Item to Link that's how you can avoid nesting to anchors. My code look like this now: <NavDropdown.Item as={Link} to="/customers">Customers</NavDropdown.Item>

HichemSeeSharp
  • 3,240
  • 2
  • 22
  • 44