I want to remove the classList whenever the route changes in Next.js, I am trying this:
React.useEffect(() => {
const activatedLink = router.query.tags
const classActivated = document.querySelector('.'+activatedLink)
if(router.asPath) {
classActivated?.classList.add('link-on')
}
else classActivated?.classList.remove('link-on')
}, [router.asPath])
Any idea how to remove the classList when the route changes?
React.useEffect(() => {
const activatedLink = router.query.tags
const classActivated = document.querySelector('.'+activatedLink)
if(router.asPath === '/some/path') {
classActivated?.classList.add('link-on')
}else{
classActivated?.classList.remove('link-on')
}
},[router.asPath])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.