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

105
Views
Cómo encontrar información de ruta principal de la ruta actual dentro de un componente

Necesito detectar la ruta /products principales desde el interior del componente FeaturedProducts.vue. Que tiene una ruta de ruta de /product-list/featured

 const routes = [ { path: "/", name: "Home", component: () => import('./Home.vue') }, { path: "/product-list", name: "Products", component: () => import('./Products.vue'), children: [ { path: '/featured', name: "FeaturedProducts", component: import('./FeaturedProducts.vue') } ] }];

¿Cómo puedo encontrar la ruta principal mediante programación en un componente?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede obtener todas las rutas usando router.getRoutes() e iterar para verificar si las rutas secundarias coinciden con su ruta actual.

 setup() { const router = useRouter(); function findParentRoute() { let found = null; router.getRoutes().forEach((r) => { (r.children || []).forEach((ch) => { if (r.path + "/" + ch.path == route.path) { found = r; } }); }); return found; } }

TENER CUIDADO

Esta solución solo funciona si coinciden las rutas completas. Si las rutas tienen parámetros, puede usar route.name en lugar de route.path

about 4 years ago · Juan Pablo Isaza 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!