How to use Active nav link/route in next js
Next Js Active Navlink Link
Problem: Next js by default not have active route system. If you are use next js then need to create custom active link system. Next js Has usePathname hook using this hook need to apply custom logic for checking is active nav link/route
Solution: This next-js-active-route package this very simple. Here need just import NavLink and use it Like default <Link> component in next js. But this package have Active feature just need to add props "activeClassName".
Demo
Authors
Installation
install with npm
install with yarn
install with pnpm
Usage/Examples
Props
Props | Type | Description |
---|---|---|
href | string | Required. it's url page url |
activeClassName | string | Required. this all classes applied when your route is active |
children | ReactNode | Required. for example <p><img src="icon.svg" /> <span>Blog</span></p> |
className | string | Optional. you can use any classNames |
exact | boolean | Optional if you want to exact match for example your path is ('/') |
*** | any | Optional that accept <Link> component |
Abtahi Hasan
Owner