DEV Community

Discussion on: Building Dynamic Breadcrumbs in NextJS

Collapse
 
stackusman profile image
stack-usman


useEffect(() => {
let splited = router.asPath.split('/')
let bread = document.getElementById("#p");
for(let i = 1; i < splited.length; i++){
bread.innerText += i > 1 ? '/' : ''
bread.innerText += splited[i]
}
document.body.appendChild(bread)
},[router])

Nice solution you provide.
but can you suggest improvement for this.