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, 2025 in Node-js by Ashutosh
• 33,350 points
578 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, 2025 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, 2025 in Node-js by Kavya
540 views
0 votes
1 answer

How would you implement routing in a dynamic Music Store application?

Implementing Routing in a Dynamic Music Store ...READ MORE

answered Feb 23, 2025 in Node-js by Kavya
651 views
0 votes
1 answer

How do you redirect a user to a different route in React Router?

Redirecting a User in React Router 1. Using ...READ MORE

answered Feb 23, 2025 in Node-js by Kavya
490 views
0 votes
1 answer
0 votes
1 answer

How would you implement a chat application using MongoDB’s data model patterns?

To implement a chat application using MongoDB’s ...READ MORE

answered Feb 23, 2025 in Node-js by Kavya
571 views
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, 2025 in Node-js by Kavya
621 views
0 votes
1 answer

How do you pass and use URL parameters in a React-Router route?

Passing and Using URL Parameters in React ...READ MORE

answered Feb 23, 2025 in Node-js by Kavya
516 views
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, 2025 in Node-js by Kavya
575 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