Home > Mobile >  how to only get child route back on next js?
how to only get child route back on next js?

Time:06-07

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...

CodePudding user response:

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());

  • Related