C
C
Ca1doz2021-11-22 21:24:31
JavaScript
Ca1doz, 2021-11-22 21:24:31

Navlink how to change clicked link color?

I want that when I click on a link, its color changes and stays the same. But after clicking on another one, it changed color, and the previous link again became the same.

jsx:

<nav className={classes.nav}>
            <div className={classes.item}>
                <NavLink to="/profile" activeClassName={classes.active}>Profile</NavLink>
            </div>
            <div className={classes.item}>
                <NavLink to="/dialogs"activeClassName={classes.active}>Messages</NavLink>
            </div>
</nav>


CSS:
.nav {
    grid-area: n;
    background-color: lightslategrey;
}

.item a {
    color: white;
    font-size: 25px;
}


Can you please tell me how to describe this in CSS?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zorca, 2021-11-23
@zorca

visited is:a:visited {}

A
Alexey Abramov, 2021-11-23
@Gvoz1

I understand that you have version 6 of the router. Now you need to do this

<NavLink
  to="/profile"
- activeClassName={classes.active}
+ className={({ isActive }) => (isActive ? classes.active : '')}
>
  Messages
</NavLink>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question