user10431099
user10431099

Reputation:

How to remove URL and keep path only?

How can I remove the URL from a string but keep the path only?

I just want to keep the path only but API returns FULL URL only.

MainMenu.jsx:47 http://dev.ffbvps.local/about/
MainMenu.jsx:47 http://dev.ffbvps.local/work/
MainMenu.jsx:47 http://dev.ffbvps.local/behind-the-scenes/
MainMenu.jsx:47 http://dev.ffbvps.local/people/
MainMenu.jsx:47 http://dev.ffbvps.local/themes/

Upvotes: 0

Views: 788

Answers (3)

Umesh
Umesh

Reputation: 13

let url

let urlObjPath = new URL("http://dev.ffbvps.local/behind-the-scenes/").pathname;
console.log(urlObjPath);

Upvotes: 0

Deepinder Singh
Deepinder Singh

Reputation: 989

const paramUrl = new URL("http://dev.ffbvps.local/about/");
console.log(paramUrl.pathname)

Upvotes: 1

Saba
Saba

Reputation: 373

If you want to have the pathname, you can use:

window.location.pathname

Upvotes: 0

Related Questions