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>

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Michal Lev`y issue is solved, I remove Children Key word

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.