Tengo esta URL generada por mi aplicación vue.js
http://localhost:8080/#/url-groups Necesito acceder a url-groups
He intentado
const firstSegment = new URL(window.location.href).pathname.split('/#/')Seguí recibiendo '/'
También he intentado:
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) ['', '']¿Puede alguien por favor corregirme?
Intente obtener el segmento hash y luego divídalo usando / como separador y finalmente obtenga el elemento de la matriz dividida:
const [,secondSegment] = new URL(window.location.href).hash.split('/')o
const segment= new URL(window.location.href).hash.replace('#/','')