B
B
BoriHagen2020-01-03 18:46:57
React
BoriHagen, 2020-01-03 18:46:57

Why is activeClassName not working in React.js?

import React from 'react';
import s from './Nav.module.css';
import { NavLink } from 'react-router-dom';

const Navbar = () => {
    return (
        <nav className={s.nav}>
            <div className={s.item}>
                <NavLink to="/profile" activeClassName={s.selected}>Profile</NavLink>
            </div>
            <div className={s.item}>
                <NavLink to="/dialogs" activeClassName={s.selected}>Dialogs</NavLink>
            </div>
            <div className={s.item}>
                <a href="/#">Music</a>
            </div>
            <div className={s.item}>
                <a href="/#">Settings</a>
            </div>
        </nav>
    )
}

export default Navbar;


activeClassName does not add any classes to the element - I looked even in the html code of the page. Tried the same. Doesn't help. activeClassName="selected"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BoriHagen, 2020-01-03
@BoriHagen

I decided by launching the project not through cmd, but through the VS Code console.

I
Ivan Novikov, 2021-09-22
@novik90

Gods!!
You just saved my monitor from death.
I already wanted out of rage why it doesn’t work, throw everything away and become a courtesan, as in that joke

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question