Reputation: 170
I want to have(created) dynamic route like as provided in nuxt docs
pages/projects/
/_id.vue
/_id/details.vue
But everytime I call url localhost/projects/1/details/
, it is rendering _id.vue
page instead of /_id/details.vue
!! How to do correctly ?
Upvotes: 3
Views: 9672
Reputation: 443
Your _id.vue structure should contain <nuxt-child>
component in order to render it's child details.vue
correctly.
Your folder structure then looks like this:
└── pages
└── projects
├── _id
│ └── details.vue
└── _id.vue
Having this folder structure produces router with setup like this:
routes: [
{
path: "/projects/:id?",
component: ProjectsId,
name: "projects-id",
children: [
{
path: "details",
component: ProjectsIdDetails,
name: "projects-id-details"
}
]
},
That means your code could look something like this:
_id.vue
<template>
<div>
<h1>(_id.vue) Project: {{ $route.params.id }}</h1>
<nuxt-child/>
</div>
</template>
<script>
export default {}
</script>
<style>
</style>
_id/details.vue
<template>
<div>
(_id/details.vue) Project: {{ $route.params.id }}
</div>
</template>
<script>
export default {}
</script>
<style>
</style>
TIP: If you come to situation where you are not sure about your routing, open your .nuxt/router.js
after nuxt build is done. There you will find function createRouter()
which will help you debug routes.
Upvotes: 5
Reputation: 9533
You have to config Nuxt-Child. Take a look https://nuxtjs.org/api/components-nuxt-child
Upvotes: 1