I’m trying to implement a simple navigation using NavLink with className and activeClassName. I have a function which renders the links
const navItem = (item) => {
const { index, title, link } = item
return (
<NavLink
className={inactiveLink}
activeClassName={activeLink}
to={link}
key={index}
>
{title}
</NavLink>
)
}
The activeLink and Inactive link are defined constants that contain tailwind strings
const activeLink =
'inline-flex items-center px-1 pt-1 text-sm font-medium text-gray-900 border-b-2 border-indigo-500'
const inactiveLink =
'inline-flex items-center px-1 pt-1 text-sm font-medium text-gray-500 border-b-2 border-transparent hover:border-gray-300 hover:text-gray-700'
I have an array of link objects
const navItems = [
{
index: 1,
title: 'Home',
link: routes.home(),
},
{
index: 2,
title: 'Sample',
link: routes.sample(),
},
{
index: 3,
title: 'Page 1',
link: routes.page1(),
},
]
Finally, in my component I have
{navItems.map((item) => {
return navItem(item)
})}
It always renders the items using the className and never uses the activeClassName.
I followed this example in the redwood documentation Active Link .
Any thoughts on what I’m doing wrong?