Home > Blockchain >  HIghlight Active Link in the Navbar , React
HIghlight Active Link in the Navbar , React

Time:08-30

This is a simple version of the problem not the actual problem. React code:

<Router>
   <Navbar/>
   <Routes>
       <Route path="/:genreId" element={<MovieList/>} />
   <Routes>
<Router>

This problem is that in the Navbar, I have several button to go the particular genre. I want to highlight active button in the Navbar (when I click "comedy" the "comedy" button should be lit up)

some solutions

  1. State => will not work if I reload
  2. Session Storage => will not work if I come be website for the first time
  3. Extract the params using the useParams Hook => this will not work since param "genreId" is available to the movieList component not the navbar
  4. Extract from the window.location => Don't want to do it since it look too ad-hock

What is the right method?

CodePudding user response:

I usually use IndexDB for that kind of stuff. To manage the IndexDB perfectly you can use localforage. You can check this link.enter image description here

Edit highlight-active-link-in-the-navbar-react

  • Related