When you are using the Functional component then follow the instruction here.
Use the above code here.
import React, { useEffect } from 'react';
import { Link } from 'react-router-dom';
const NavItems = () => {
let pathname = window.location.pathname;
useEffect(() => {
pathname = window.location.pathname;
}, [window.location.pathname]);
return (
<>
<li className="px-4">
<Link to="/home" className={`${pathname.match('/home') ? 'link-active' : ''}`}>Home</Link>
</li>
<li className="px-4">
<Link to="/about-me" className={`${pathname.match('/about-me') ? 'link-active' : ''}`}>About-me</Link>
</li>
<li className="px-4">
<Link to="/skill" className={`${pathname.match('/skill') ? 'link-active' : ''}`}>Skill</Link>
</li>
<li className="px-4">
<Link to="/protfolio" className={`${pathname.match('/protfolio') ? 'link-active' : ''}`}>Protfolio</Link>
</li>
<li className="pl-4">
<Link to="/contact" className={`${pathname.match('/contact') ? 'link-active' : ''}`}>Contact</Link>
</li>
</>
);
}
export default NavItems;
--- Thanks ---