How would you use NavLink to style active navigation links in a React application

0 votes
With the help of code and examples can you tell me How would you use NavLink to style active navigation links in a React application?
Feb 22 in Node-js by Ashutosh
• 20,830 points
72 views

1 answer to this question.

0 votes

You can use the <NavLink> component to style active navigation links.

Implementation

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

const Navbar = () => {

  return (

    <nav>

      <NavLink to="/" className={({ isActive }) => isActive ? "active-link" : ""}>New</NavLink>

      <NavLink to="/about" className={({ isActive }) => isActive ? "active-link" : ""}>Home</NavLink>

    </nav>

  );

};

export default Navbar;

CSS Styling

.active-link {

  font-weight: bold;

  color: red;

}

answered Feb 23 by Kavya

Related Questions In Node-js

0 votes
1 answer

How would you model a one-to-many relationship in MongoDB?

In MongoDB, a one-to-many relationship can be ...READ MORE

answered Feb 22 in Node-js by Kavya
46 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to use executables from a package installed locally in node_modules?

Hello @kartik, Use the npm bin command to get the ...READ MORE

answered Jul 13, 2020 in Node-js by Niroj
• 82,840 points
1,686 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to set read concern in MongoDB?

In MongoDB, you can set read concern ...READ MORE

answered Feb 23 in Node-js by Kavya
59 views
0 votes
1 answer
0 votes
1 answer

How do you implement routing in a React application?

Implementing Routing in a React Application (React ...READ MORE

answered Feb 23 in Node-js by Kavya
67 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP