Home > database >  Remove / from pathname
Remove / from pathname

Time:09-21

I'm creating an application where the user can see at the top of the page the name of the current page he is on. I was able to extract the page name through the useLocation hook. But the problem is that the pathname comes with / and when I put it to show on the page the page name comes out, for example: My page: /mypage. What I wanted was that it was possible to just take it, like this: My page: my page.

CodePudding user response:

Use .slice

const string = '/mypage'
const newString = string.slice(1)
console.log(newString)

  • Related