我正在使用Vue-router,并且我需要使用嵌套路由,所以我写了Children关键字来引用子组件页面,所以我的问题是当我单击Link时,我的当前URL被嵌套替换路由并使用ID,但不加载我的组件,当我将Router-Linke更改为另一个未嵌套的组件时,它将加载该组件,所以我问我的错误是什么?
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>
Nested routes旨在促进组件嵌套(请看第一张“图片”)
您需要在<router-view>
组件中包含target.vue
...
如果您不希望在TargetDetails.vue
内呈现target.vue
的内容,请不要使用children
配置,而是改用target.vue
顶级路由。