[英]Nuxt nested pages
Having this directories:有这个目录:
|-- pages
|--page1
| |--index.vue
| |--child1.vue
| |--child2.vue
|
|--page2
I am navigating to localhost:3000/page1
and pages/page1/index.vue
is being loaded.我正在导航到localhost:3000/page1
并且正在加载pages/page1/index.vue
。
Now I want to place two links inside index.vue
so I can render the children components inside its parent index.vue
现在我想在index.vue
中放置两个链接,这样我就可以在其父index.vue
中渲染子组件
index.vue索引.vue
<template>
<v-container>
<h1>I am the parent view</h1>
<nav>
<ul>
<li>
<NuxtLink to="page1/child1">Child</NuxtLink>
</li>
<li>
<NuxtLink to="page1/child2">Child 2</NuxtLink>
</li>
</ul>
</nav>
<NuxtChild />
</v-container>
</template>
<script>
export default {
}
</script>
child1.vue child1.vue
<template>
<v-container>
<h5>child1</h5>
</v-container>
</template>
child2.vue child2.vue
<template>
<v-container>
<h5>child2</h5>
</v-container>
</template>
however when I click the links, I get redirected to localhost:3000/page1/child1
so I lose the layout from parent.但是,当我单击链接时,我被重定向到localhost:3000/page1/child1
所以我失去了父级的布局。
Am I missing anything?我错过了什么吗?
pages/page1.vue
seems to be missing. pages/page1.vue
似乎不见了。
<template>
<div>
<h1>I am the parent view</h1>
<NuxtChild />
</div>
</template>
You need to do the following changes:您需要进行以下更改:
pages/page1/index.vue
to pages/page1.vue
重命名pages/page1/index.vue
并将其移动到pages/page1.vue
"page1/child1"
must become "/page1/child1"
例如, "page1/child1"
必须变为"/page1/child1"
pages/page1/index.vue
(可选)如果想在没有选择子路由的情况下在 NuxtChild 中显示一些内容,那么将这些内容放在pages/page1/index.vue
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.