Breadcrumbs are a website navigation tool that allows users to see their current page's "stack" of how it is nested under any parent pages. Users c...
For further actions, you may consider blocking this person and/or reporting abuse
Nice one! But not sure what
asPathParts
- there is no definition of it and it's being used.Oops! You are correct. That was an artifact of my copying from my “real” code and trying to refactor the names to be more tutorial friendly. I believe I fixed it.
I am getting an error re: async:
I followed the eslint guidance to fix and now it says that
useEffect is not defined
. Per chance do you have the full code I could take a look at to see what I am doing wrong? Thanks for writing this btw. Great stuff. Cheers!I fix it by doing this instead
inside the Crumb Component before the if( last) ....
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.
This helped. I didn't need text generators, useEffect, etc. because I just pass in the param and query to the breadcrumbitem and conditionally pull dynamic data based on the param name (e.g. [post_id]) and its value from the query. This post really helped get me going. Thanks!
Hey! Nice tutorial, thank you for that, great work!
I wonder how the breadcrumb component gets notified about the changing route, because it seems like you don´t even have to listen to some events or similiar.
Could you tell me how the breadcrumb component knows when to update itself? (and which part of your provided code is responsible for that?)
Kind regards,
Jendrik
it updates it self with the useMemo's dependencies array [router.asPath, router.pathname, router.query, getTextGenerator, getDefaultTextGenerator]
I think you could take off the router.query from the dependencies since the router.query is an object and will not know if the values of that object are changing but will have to try that
Nice article.
Is there any github repo to clone?
Thanks
Hi, can you provide me with the git address of the code? Thank you very much!
Hey @dan_starner, it seems like this wouldn't work with catchall routes in Next, as creating the crumblist throws an error.
This code is not working for me... it shows all kind of errors.