I have this URL generated by my vue.js app
http://localhost:8080/#/url-groups
I need to access url-groups
I've tried
const firstSegment = new URL(window.location.href).pathname.split('/#/')
I kept getting '/'
I've also tried :
const firstSegment = new URL(window.location.href).pathname.split('#'); console.log(firstSegment);
VM21687:1 ['/']
const firstSegment = new URL(window.location.href).pathname.split('/#/'); console.log(firstSegment);
VM21719:1 ['/']
const firstSegment = new URL(window.location.href).pathname.split('/'); console.log(firstSegment);
VM21751:1 (2) ['', '']
Can someone pls correct me ?
Try out to get the hash segment then split using / as separator finally get the element of the splitted array :
const [,secondSegment] = new URL(window.location.href).hash.split('/')
or
const segment= new URL(window.location.href).hash.replace('#/','')