Vue-router nested route not loading my component page
Asked Answered
L

1

6

I am using Vue-router and I was needing to use a nested route, so what I did I wrote Children Key word to reference for a child component page, so my problem is when I click on Link my current URL replaced with nested route and with an ID but not load my component, and when I change Router-Linke to another component that is not nested it will load component, so I ask what are my mistakes?

route.js

{
        path: '/targets',
        name: 'target',
        component: () =>
            import ( /* webpackChunkName: "target" */ '@/views/admin/Target.vue'),
            meta: {
                middleware: [
                    auth
                ],
                title: "Targets"
            },
            children:[
                {
                    path: '/targets/:id/details',
                    name: 'target-details',
                    props: true,
                    component: () =>
                        import ( /* webpackChunkName: "target" */ '@/views/admin/TargetDetails.vue'),
                        meta: {
                            middleware: [
                                auth
                            ],
                            title: "TargetDetails"
                        }
                },
            ]
    },

target.vue

<template>
<div>
 <li class="clearfix" v-for="domain in domains" :key="domain.domain_id">{{ domain.domain }} 
                            <router-link class="more" 
                                :to="{ 
                                        name: 'target-details', 
                                        params: { 
                                            id: domain.domain_id 
                                        } 
                                    }"  >Target details <i class="fa fa-angle-right"></i>
                            </router-link>
                        </li>
</div>
</template>

TargetDetails.vue

<template>
   <div class="page-output">
      <h1>Target Details</h1>
   </div>
</template>
Limey answered 7/1, 2020 at 13:1 Comment(0)
M
17

Nested routes are designed to facilitate component nesting (look at the 1st "picture")

You need to include <router-view> in your target.vue component...

If you don't want content of TargetDetails.vue rendered inside target.vue, dont use children config and make a target.vue top level route instead.

Mcguire answered 7/1, 2020 at 13:9 Comment(1)
Thanks @Michal Lev`y issue is solved, I remove Children Key wordLimey

© 2022 - 2024 — McMap. All rights reserved.