The navigation bar does not display the CSS when in the active state

I created a navigation bar in ReactJS and I need the tabs to stay highlighted when clicked, but the styles are not applying correctly. I have double-checked that the stylesheet is linked properly based on the Reactjs file structure.

For reference, I used this example: https://codepen.io/k3no/pen/OXgXOb?editors=0110

Navbar.js

import React,{useState} from 'react';
import { Navbar,Container, Nav } from "react-bootstrap";
import {Link, BrowserRouter as Router} from 'react-router-dom';

const NavbarComponent = () => {

return (
    <>
              
            <nav variant='pills' className="navbar navbar-default navbar-static-top">
            <ul  className="nav nav-pills">
                <li >
                <Link activeclassname="active" to="/grocery">Grocery</Link>
                </li>
                <li >
                <Link activeclassname="active" to="/fashion">Fashion</Link>
                </li>
                <li >
                <Link activeclassname="active" to="/beauty">Beauty</Link>
                </li>
                <li >
                <Link activeclassname="active" to="/footwear">Footwear</Link>
                </li>
            </ul>
            </nav>
        
 
    </>
    )
  }

  export default NavbarComponent;

index.css

nav {
border-bottom: 4px solid black;
text-align: center;
position: relative;
top: 0;
width: 100%;
background: white;
}

nav ul {
list-style-type: none;
margin: 0;
padding: 0;
}

nav li {
display: inline-block;
padding-top: 16px;
padding-bottom: 16px;
}

nav a {
text-decoration: none;
color: black;
font-weight: bold;
padding: 16px 32px;
}


.navbar .nav-pills >li >a {
color: black;
}
.navbar .nav-pills > li > a:hover {
 background-color: gold;
 color: black;
}

.navbar .nav-pills .active {
background-color: palevioletred;
color:Black ;
font-weight:bold;
}

Reference link: https://codepen.io/k3no/pen/OXgXOb?editors=0110

I am unable to identify the cause of the issue.

Answer №1

To enable the use of the activeClassName property, make sure to utilize the NavLink component from the react-router-dom library instead of the Link component.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Create a vibrant stroke and conclude with a circular marker beneath the content with CSS

Can you create a vibrant line with a dot underneath text using CSS, similar to the example shown in the image? The underline should begin with some spacing or padding. .underline { text-decoration: underline; text-underline-offset: 10px; displa ...

How to access the ID value from the URL within a different component that was passed as a prop in

I have a scenario where I am building a reusable component with two child components in the following flow: Child Component 1 -> Parent Component -> Super Parent Main Component In the child component, I define a prop called 'url' which is ...

Tips for utilizing a unique JavaScript function with Mongoose's findByIdAndUpdate by incorporating $set:

Is it possible to update a database document using a custom JavaScript function? I am aware of the traditional method where you find -> update the document with JavaScript -> save, but this can lead to issues with concurrent data updates. Below is an ...

Gulp: executing a task with no specified output location

I am attempting to create a straightforward task to display the file size for each file in an array of paths using the gulp-size plugin, as shown below: var gulp = require('gulp') var size = require('gulp-size') gulp.task('size&a ...

Combining two elements in a React application

Having a collection of assets and their quantities: const bag = { eth: 50, btc: 30, kla: 10, set: 5, ova: 5 }; const assetList = { eth: { name: "Ethereum", icon: "urlhere", colour: "#030", text: "light&q ...

Changing the width of an SVG path from 0 to 100% using CSS

I have an SVG design of wires that I want to animate the width from "0 to 100%", but I'm having trouble achieving this effect. It's easy to do with a div element, but not with an SVG image. Below is my code snippet: svg path { animation: f ...

Finding the offsetWidth (or similar measurement) for a list item (LI) element

Can jQuery be used to determine the width of an element? alert($("#theList li:eq(0)").offsetWidth); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ol id="theList"> <li>The quick brown ...

Is it possible to use CSS to create a gap between the cursor and the placeholder text within an input field?

Could you please assist me with a bug I have encountered on an older version of Firefox for OSX (37.0.2)? I have included a screenshot of the issue here: https://i.sstatic.net/dzK0G.png Is there a way to use css to move the first character of the placehol ...

Looking for a solution to this problem - I'm interested in creating a circular image with the help of tailwind css

https://i.sstatic.net/4s3Hg.jpg <div className='flex justify-between w-full'> <div className='px-1 w-full'> <img src='https://images.unsplash.com/photo-1566275529824-cca6d008f3da?ixlib=rb-4.0.3& ...

Establish a comprehensive background for your Angular project

I've been struggling to figure out how to set a background image for my entire angular project. I've tried using global css and the app.component.css file, but it only sets the background for the component area. Here is a snippet from my global ...

Why are JS & jQuery's inArray() and indexOf() functions not functioning correctly when indexes are strings?

Here is an example of an array: var arr = []; arr['A string'] = '123'; arr['Another string'] = '456'; I am attempting to find the index of either '123' or '456'. Both methods below are returnin ...

I aim to prevent users from liking a post multiple times within Firebase

I came up with this code snippet to implement the Like functionality: /*Incrementing by 1 every time a user submits a like*/ db.collection("post").doc(postId).update({ likes: increment }) /*Collecting the UID of the user who submitted the l ...

Issue with Next.js hook: Uncaught TypeError - Unable to define properties of undefined (setting 'type')

Encountered an error while attempting to build my nextjs app. Strangely, this error wasn't present in the previous version of the app. I didn't make any changes to the config files, just added a few animation libraries and that's all, along ...

Using json_encode with chart.js will not produce the desired result

I am attempting to utilize chart.js (newest version) to generate a pie chart. I have constructed an array that I intend to use as the data input for the chart. This is the PHP code snippet: <?php if($os != null) { $tiposOs = array('Orçamento ...

When using Material UI, I ran into an issue where my Card Component was being added to my Appbar. To improve user interaction, I desire for the cards to only appear once

The formatting of the naming conventions is incorrect. Please disregard those. Snippet of code for the Appbar: const useStyles = makeStyles((theme) => ({ root: { flexGrow: 1 }, title: { flexGrow: 1 } })); export default function Appp() ...

Obtain an item from an array by utilizing the property with Lodash _.find

I currently have an array of objects called memberToChange.checkboxes: ICheckbox[] structured like this: https://i.stack.imgur.com/LyKVv.png Within this setup, there is also a variable named internalNumber with the value "3419". My objective is to locate ...

Setting up Express routes in a separate file from the main one: a step-by-step

My goal is to organize my routes separately from the main app.js file using the following file structure. I attempted to create a api/user/ post API but encountered a 404 error. Any suggestions on how to resolve this issue with the given file structure? . ...

Error encountered: A missing semicolon was detected before a statement while executing code within a for

Although this question may have already been asked, I am struggling to understand why it is not working as expected. I simply want to increment the markers array within a for loop and then add each marker to the vector source using vectorSource.addFeature ...

Dealing with unresponsive sidenav in MaterializeCSS when trying to click and pop-out with React

One particular challenge I am encountering relates to user experience when it comes to authentication. If a user is authenticated, the AuthLinks will be displayed, but if not, the GuestLinks will show instead. The issue arises when switching to responsive ...

What kind of type is recommended to use when working with async dispatch in coding?

For my TypeScript and React project, I am currently working on an action file called loginAction.tsx. In this file, there is a specific line of code that handles the login functionality: export const login = (obj) => async dispatch => { dispatch( ...