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

255
Views
Renderizar hijo predeterminado vue-router 4

Me gustaría preguntar sobre el niño predeterminado de representación para la vista. Sé que existe un tema con un problema similar, pero estoy bastante seguro de que fue para VUE2 y vue-router anteriores. Tengo problemas para mostrar el elemento secundario predeterminado para la categoría de vista. Cuando iba a <router-link :to="{ name: routeName, params: { category: item.id } } todo funciona bien excepto <router-view /> está vacío...

Se me ocurrió una solución con beforeUpdate(),beforeCreate() pero parece como reinventar la rueda. Si voy a /category/{id} y luego a /category/{id}/room/{id} y regreso una página, se mostrará la vista predeterminada

¿Cómo hacer que el niño predeterminado se cargue después de ir a /category/{id}?

enrutador.js

 { path: '/category/:category', name: 'Category', props: true, component: Category, children: [ { path: '', name: 'FavouriteDevicesInCategory', component: Devices, props: true, }, { path: 'room/:room', name: 'Devices', component: Devices, props: true, }, ], },

Categoría.vue - ver

 <template> <div class="control"> <div class="left"> [...] </div> <div class="right"> <router-view /> </div> </div> </template> <script> export default { props: ['category', 'room'], /** generate default router-view */ beforeUpdate() { this.$router.push(''); }, beforeCreate() { this.$router.push(''); }, };
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Si su componente predeterminado es Category , debe crear las rutas de esta manera:

 { path: '/category', name: 'Category', props: true, component: Category, children: [ { path: '/:categoryId', name: 'FavouriteDevicesInCategory', component: Devices, props: true, }, { path: 'room/:roomId', name: 'Devices', component: Devices, props: true, }, ], },

De forma predeterminada, representará el componente Category y, si agrega una id a la URL, irá al componente Devices .

about 4 years ago · Juan Pablo Isaza Report

0

Creo que encontré una solución, un poco desordenada, pero parece ser la mejor solución a este problema.

 { path: '/category/:category', // name: 'Category', props: true, component: Category, children: [ { path: '', name: 'Category', component: Devices, props: true, }, { path: 'room/:room', name: 'Devices', component: Devices, props: true, }, ], },
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!