Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

NavLink

// React Router v6
import { NavLink } from 'react-router-dom';

function NavBar() {
  // inline or css classes
  let activeStyle = { color: 'green', textDecoration: 'underline' };
  let activeClass = 'activated';

  return (
    <nav>
      <ul>
        <li>
          <NavLink
            to='messages'
            style={({ isActive }) => isActive ? activeStyle : undefined}>
            Messages
          </NavLink>
        </li>
        <li>
          <NavLink
            to='tasks'
            className={({ isActive }) => isActive ? activeClass : undefined}>
            Tasks
          </NavLink>
        </li>
      </ul>
    </nav>
  );
}
// Special kind of <Link> that knows when it is 'active'
// the styling applies to a <NavLink> when route it links to
// is currently selected.
/* 
 index.css
 	a, .nav-link { color: 'blue', text-decoration: 'none' }
    .activated { color: 'green', text-decoration: 'underline' }
*/

// React Router v5
function NavBar() {  
  return (
    <nav>
      <ul>
        <li>
          <NavLink
            to='/messages'
            style={{ color: 'blue', textDecoration: 'none' }}
    		activeStyle={{ color: 'green', textDecoration: 'underline' }}>
            Messages
          </NavLink>
        </li>
        <li>
          <NavLink
            to='tasks'
            className='nav-link'
			activeClassName='activated'>
            Tasks
          </NavLink>
        </li>
      </ul>
    </nav>
  );
}
Comment

navlink

<NavLink to="/about">About</NavLink>
Comment

NavLink

<NavLink to="/faq" activeClassName="selected">
  FAQs
</NavLink>
Comment

PREVIOUS NEXT
Code Example
Javascript :: TYPING TEXT USING JS 
Javascript :: average of numbers 
Javascript :: remove everything from mongodb databaase mongoose 
Javascript :: how to assert in javascript 
Javascript :: get data from json placeholder 
Javascript :: equality operator javascript 
Javascript :: how to get first element of an array in javascript 
Javascript :: 7) Change cursor:pointer at checkboxes in java script 
Javascript :: nextjs docs 
Javascript :: vue axios post return json data 
Javascript :: react toastify is not working 
Javascript :: blob to text javascript 
Javascript :: delete from list javascript 
Javascript :: javaScript setHours() Method 
Javascript :: spring react 
Javascript :: how to use a regex expression in kibana query 
Javascript :: create object from array 
Javascript :: number to float js 
Javascript :: jquery select input 
Javascript :: see all set variables chrome 
Javascript :: react component will mount new method 
Javascript :: less than or equal to javascript 
Javascript :: working with json in javascript 
Javascript :: lifecycles if reactjs 
Javascript :: Substring in Javascript using substring 
Javascript :: find duplicates and their count in an array javascript 
Javascript :: vue 3 create app 
Javascript :: ajax is not a function 
Javascript :: anchor click event angular refresh page 
Javascript :: define an async function 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =