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

114
Views
How to find parent route info of the current route within a component

I need to detect parent route /products from inside of the FeaturedProducts.vue component. Which has a route path of /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')           
      }
    ]
  }];

How can I find the parent route programmatically in a component?

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

0

You can get all routes using router.getRoutes() and iterate to check if child routes matches your current route.

 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;
   }
 }

BEWARE

This solution works only if full-paths are matched. If paths have parameters you can use route.name instead of 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!