【发布时间】:2021-01-11 17:27:26
【问题描述】:
可以从父组件的子组件中排除 pages 目录中的一些嵌套组件吗?我需要一些嵌套组件(nested-a 和 nested-b)在父组件(_id.vue)内部渲染,一些嵌套组件(独立嵌套)用作独立页面,不在_id.vue 内部渲染,仅使用父组件在路线中。
所以我的目标是实现这些路线:
-
/account/{id}- 主页 -
/account/{id}/standalone-nested- 独立页面,不在父页面内呈现 -
/account/{id}/nested-a和/account/{id}/nested-b- 嵌套组件呈现在父级中
这是我的目录树:
pages
├── account
│ ├── _id
│ │ ├── nested-a.vue
│ │ ├── nested-b.vue
│ │ └── standalone.vue
│ ├── _id.vue
│ └── index.vue
└── index.vue
生成以下路由器:
{
path: "/en/account/:id",
component: _45553d28,
name: "account-id___en",
children: [{
path: "nested-a",
component: _7b67c342,
name: "account-id-nested-a___en"
}, {
path: "nested-b",
component: _7b75dac3,
name: "account-id-nested-b___en"
}, {
path: "standalone",
component: _6884b488,
name: "account-id-standalone___en"
}]
}
在我的父组件_id.vue 中,我使用<NuxtChild /> 来确保在此组件内呈现嵌套组件,但我不知道如何告诉nuxt 哪些嵌套组件仅在此标记内呈现。
这是我的 MWE:https://github.com/DenisStephanov92/nuxt-routing-sample
感谢您的建议。
【问题讨论】:
-
可以分享MWE
-
@Chandan 嗨,谢谢你的努力,我在 github 上添加了 MWE 的链接
-
@DenisStephanov 不应该把这个
_id.vue放在名为_id的文件夹中id.vue!! -
@HardikShah 没有这会导致从路由器中删除所有子节点
标签: javascript vuejs2 nuxt.js vue-router