active
가 추가 된다.import React from 'react';
import { NavLink } from 'react-router-dom';
export default function Header() {
const activeStyle = {
color: 'orange',
};
const activeClassName = 'active';
return (
<div>
<NavLink
to='/'
style={({ isActive }) => (isActive ? activeStyle : undefined)}
>
Index
</NavLink>
<NavLink
to='/home'
className={({ isActive }) => (isActive ? activeClassName : undefined)}
>
Home
</NavLink>
</div>
);
}
Reference
React Router - NavLink