最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Dynamic routing is not working in nuxt? - Stack Overflow

programmeradmin0浏览0评论

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 ?

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 ?

Share Improve this question edited May 30, 2018 at 6:57 noder asked May 30, 2018 at 4:20 nodernoder 1701 silver badge9 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Your _id.vue structure should contain <nuxt-child> ponent 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?",
        ponent: ProjectsId,
        name: "projects-id",
        children: [
            {
                path: "details",
                ponent: 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 e 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.

You have to config Nuxt-Child. Take a look https://nuxtjs/api/ponents-nuxt-child

发布评论

评论列表(0)

  1. 暂无评论