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

136
Views
Replace parent component entirely in child route

I'm trying to nest routes with the VueJS router (next/4.x) so that the child route completely replaces the parent component.

The example given here assumes that for each sub route, there's a sub component being rendered, but I'd like to replace the component User entirely when navigating to /user/johnny/profile instead of rendering Profile within the User component.

/user/johnny/profile                     /user/johnny/posts
+------------------+                  +-----------------+
| User             |                  | User            |
| +--------------+ |                  | +-------------+ |
| | Profile      | |  +------------>  | | Posts       | |
| |              | |                  | |             | |
| +--------------+ |                  | +-------------+ |
+------------------+                  +-----------------+

I tried to omit the <router-view> tag in User, but that just doesn't render Profile when navigating to /user/johnny/profile (most likely because it doesn't find a place to render the Profile component).

The only thing that seems to be working is to check the route name in UserComponent and hide <router-view> when the route is /user/johnny or hide the markup for UserComponent and just show <router-view when the child route is active. I wonder if there's a better way to do this. For instance, it would be nice if the <router-view> could just be removed and the ProfileComponents finds the next closest parent's <router-view> to render itself, but I haven't found ways to configure this or examples that would suggest that's possible...

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

0

What you need to is to create both the Profile and Posts components as childlren routes to user's route.

So, in the user's component, you only need to define the in the template's tag.

Example:

route.js

const routes = [
  {
    path: '/user',
    name: 'user',
    component: UserComponent,
    children: [
      {
        path: '/profile',
        name: 'user-profile',
        component: UserProfileComponent
      },
      {
        path: '/post',
        name: 'user-post',
        component: UserPostComponent
      }
    ]
  }
]

UserComponent.vue

<template>
  <router-view />
</template>
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!