Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

activeClassName react router

// Before React Router v6, to set class for active element we used:
 <NavLink to="/start" activeClassName="HERE NAME CLASS WHEN COMPONENT IS ACTIVE">start</NavLink>

// Now, instead of activeClassName="HERE..." use:
className={(navLinkObj) => "start-selected_" + navLinkObj.isActive}

// And then in css use:
.start-selected_true {
  background-color: red;
  border-bottom: 5px solid yellow;
}

// Also, you can do the same for inactive link. In css use:
.start-selected_false {
  background-color: blue;
  border-bottom: 5px dashed green;
}

// PS: (navLinkObj.isActive) returns true if element is active and false if element is not
// PS: I really advice you to check out documentation of React Router. It helped me :)
// React Router Documentation: https://v5.reactrouter.com/web/api
Comment

activeclassname in react router v6

export function Header() {
  return (
    <header>
      <ul>
        <li>
          <NavLink className={(navData) => navData.isActive ? "active" : "" } to="/about" />
        </li>
        <li>
          <NavLink className={(navData) => navData.isActive ? "active" : "" } to="/profile" />
        </li>
      </ul>
    </header>
  )
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: react native text capitalize 
Javascript :: prepend to array javascript 
Javascript :: reactive forms change event in angular 
Javascript :: jquery get left position 
Javascript :: how to set background colour i js inline stylel 
Javascript :: find object in array javascript with property 
Javascript :: express redirect 
Javascript :: toggle class javascript stack overflow 
Javascript :: type of javascript 
Javascript :: getelementsbyclassname remove class 
Javascript :: for range python javascript 
Javascript :: remove duplicate items from array 
Javascript :: how to find length of array in javascript without using length method 
Javascript :: javascript check if string contains character 
Javascript :: vuex use state in action 
Javascript :: javascript calculate 24 hours ago 
Javascript :: tailwind config 
Javascript :: parse csv javascript 
Javascript :: jquery select all checkboxes 
Javascript :: javascript get value 
Javascript :: javascript string startswith 
Javascript :: Set timeouts to XMLHttpRequests in javascript 
Javascript :: expo react native 
Javascript :: mmap() failed: [12] Cannot allocate memory composer 
Javascript :: javascript generate random numbers 
Javascript :: react native android padding style 
Javascript :: react font awesome 
Javascript :: angular toaster 
Javascript :: how to double array data in js 
Javascript :: square root javascript 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =