Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to only get child route back on next js?

Not sure this title is worded right. Next JS project and am making a custom breadcrumb component. everything i need looks good so far except i have a /people page then /people/roles page. i am trying to get a const to pick up only the roles part.

so far i have this

const x = router.pathname  == "/dashboard" ? 'home' : router.pathname
const [subTitle, setSubTitle] = x.split('/')

this just brings back / i’m thinking theres a regex way for this but that’s not my strongest subject. i think ideally i want a way to split the pathname into an array…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use the pop method after splitting, you will get only the last position of the array.

const x = "something/something1/something2"

console.log(x.split("/").pop());
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading