Next.js Discord

Discord Forum

next/navigation update?

Answered
Varun posted this in #help-forum
Open in Discord
useEffect(() => {
console.log("switching tabs")
console.log(router.pathname)
// Set the active tab based on the current pathname
setActiveTab(router.pathname);
}, [router.pathname]);

in my sidebar component I am tracking route changes like this to highlight my sidebar. however this hook only gets called on page reload not when I change paths using router.push
Answered by Arinji
And put path in the deps arrays
View full answer

6 Replies

Don't do router.pathname
const path = usePathname()
And put path in the deps arrays
Answer
@Varun
Bet thx
@Varun Bet thx
make a solution :D