Answer the question
In order to leave comments, you need to log in
React Router 4: How to put actleClassName for two links?
Tell me how to make it so that activeClassName
one link is placed, depending on the route?
If you go to the main section - /
or to /accounts
, a class was set for one <NavLink>
There is a section with accounts. If you go to the main route, a section of accounts opens as if you go to the section/accounts
Answer the question
In order to leave comments, you need to log in
I do like this,
import React from "react";
import { Link } from 'react-router-dom'
export default class NavLink extends React.Component{
constructor(props) {
super(props);
}
render() {
let activeStyle;
let url = window.location.hash;
url = url.replace('#/','/')
if (url == this.props.to){
activeStyle = { opacity: 0.5 }
}
return <Link {...this.props} style={activeStyle} />
}
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question