Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

377
Views
Vuejs: Acceder a un segmento de URL específico

Tengo una ruta/URL:

Ex. http://localhost:8080/qr-códigos

Quiero acceder al primer segmento

qr-codes

Cómo puedo hacer eso ?

Solía ser capaz de hacer algo como esto en Laravel

Solicitud::segmento(1);

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

const getUrlPathSegments = () => ( (new URL(window.location.href)).pathname.split('/').filter(Boolean) )

por ejemplo, cuando llama a la función en la página actual de stackoverflow, obtiene:

 getUrlPathSegments() === ['questions', '70427242', 'vuejs-accessing-specific-url-segment'] getUrlPathSegments()[0] === 'questions'
over 4 years ago · Santiago Trujillo Report

0

Usando URL.pathname y String#split :

 const str = 'http://localhost:8080/qr-codes'; const firstSegment = (new URL(str)).pathname.split('/')[1]; console.log(firstSegment);

demostración de Vue:

 new Vue({ el: "#app", computed: { path: function() { const firstSegment = (new URL(window.location.href)).pathname.split('/')[1]; return `${firstSegment}/create`; } } });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="app">{{path}}</div>

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!