Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
Vue router get full path based on nested route

I created nested routes for vue router, and I am using that routes for data to create navigation menu. And for the 'router-link :to=' i am currently using route.path. Issue with that is that that is only part of the path and want to put absolute path that includes parents paths aswell. Is there some way to do this. I also tried to iterate over all routes and to set some property that will include parent paths, but i couldnt write good function.

{ path:'/meteorologija', name:'meteorologija', component:()=>import('../pages/BlogPage'), children:[
        { 
            path:'/meteorolosko-bdenje', name:'meteorolosko bdenje', component:()=>import('../pages/BlogPage'), 
            children:[
                { path:'/aktuelni-podaci', name:'aktuelni podaci', component:()=>import('../pages/BlogPage'),
                    children:[
                        { path:'/podaci', name:'Podaci', component:()=>import('../pages/BlogPage') },
                        { path:'/trenutne-temerature', name:'Trenutne temperature', component:()=>import('../pages/BlogPage') },  
                        { path:'/ekstremne-temperature', name:'Ekstremne Temperature', component:()=>import('../pages/BlogPage') },  
                        { path:'/pritisak', name:'Pritisak', component:()=>import('../pages/BlogPage') },  
                        { path:'/vjetar', name:'Vjetar', component:()=>import('../pages/BlogPage') },  
                        { path:'/kolicina-padavina', name:'Kolicina padavina', component:()=>import('../pages/BlogPage') },  
                        { path:'/radarska-slika', name:'Radarska Slika', component:()=>import('../pages/BlogPage') },  


                    ] 
                },

This is the function that i am trying to write that will get path of deeply nested object that includes paths of all parent objects

 t(routes, path={}){
       routes.forEach((r,i)=>{
          if(r.children){
              // path+= r.path;
              this.t(r.children, path);
          }
       });
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can access them within your component like this: this.$route.path.matched, it will give you an array of current matched routes, so lets say you are in /meteorologija/meteorolosko-bdenje/aktuelni-podaci/podaci path, then it will return somethin like this (it will also contain some other info):

[
    { path:'/meteorologija', name:'meteorologija' },
    { path:'/meteorolosko-bdenje', name:'meteorolosko bdenje' },
    { path:'/aktuelni-podaci', name:'aktuelni podaci' },
    { path:'/podaci', name:'Podaci' },
]

So i took a second look at your code and found this, you should not have leading slash in your children paths, so you should change it like this:

{ path:'/meteorologija', name:'meteorologija', component:()=>import('../pages/BlogPage'), children:[
        { 
            path:'meteorolosko-bdenje', name:'meteorolosko bdenje', component:()=>import('../pages/BlogPage'), 
            children:[
                { path:'aktuelni-podaci', name:'aktuelni podaci', component:()=>import('../pages/BlogPage'),
                    children:[
                        { path:'podaci', name:'Podaci', component:()=>import('../pages/BlogPage') },
                        { path:'trenutne-temerature', name:'Trenutne temperature', component:()=>import('../pages/BlogPage') },  
                        { path:'ekstremne-temperature', name:'Ekstremne Temperature', component:()=>import('../pages/BlogPage') },  
                        { path:'pritisak', name:'Pritisak', component:()=>import('../pages/BlogPage') },  
                        { path:'vjetar', name:'Vjetar', component:()=>import('../pages/BlogPage') },  
                        { path:'kolicina-padavina', name:'Kolicina padavina', component:()=>import('../pages/BlogPage') },  
                        { path:'radarska-slika', name:'Radarska Slika', component:()=>import('../pages/BlogPage') },  


                    ] 
                },
about 4 years ago · Juan Pablo Isaza Relatório

0

Did you try with

this.$route.fullPath
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda