Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue-router nested route not loading my component page

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>
like image 224
Omda Avatar asked Jan 07 '20 13:01

Omda


1 Answers

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.

like image 149
Michal Levý Avatar answered Nov 11 '22 03:11

Michal Levý