【问题标题】:Nuxt - un-nest page from nuxt-childNuxt - 来自 nuxt-child 的非嵌套页面
【发布时间】:2020-02-03 11:20:28
【问题描述】:

我有以下结构

categories/_tag/_post

目前在 Nuxt 中是这样的:

/categories.vue
/categories/_tag.vue
/categories/index.vue            (blank file which shows when the /categories page loads)
/categories/_tag/_post.vue

categories 中有一个nuxt-child 组件,因此_tag 页面会在其中加载。

我遇到的问题是 _post 页面也在 categories nuxt-child 内部加载,而不是在它自己的页面上。

我希望像这样加载视图:

【问题讨论】:

    标签: nuxt.js


    【解决方案1】:

    您需要使用命名视图。

    可以在此处找到示例 https://nuxtjs.org/examples/named-views/

    这里的关键在nuxt.config.js中

    export default {
      router: {
        extendRoutes (routes, resolve) {
          const indexIndex = routes.findIndex(route => route.name === 'index')
          let index = routes[indexIndex].children.findIndex(route => route.name === 'index-child-id')
          routes[indexIndex].children[index] = {
            ...routes[indexIndex].children[index],
            components: {
              default: routes[indexIndex].children[index].component,
              left: resolve(__dirname, 'components/childLeft.vue')
            },
            chunkNames: {
              left: 'components/childLeft'
            }
          }
    
          index = routes.findIndex(route => route.name === 'main')
          routes[index] = {
            ...routes[index],
            components: {
              default: routes[index].component,
              top: resolve(__dirname, 'components/mainTop.vue')
            },
            chunkNames: {
              top: 'components/mainTop'
            }
          }
        }
      }
    }
    ``
    

    【讨论】:

      猜你喜欢
      • 2022-09-23
      • 1970-01-01
      • 1970-01-01
      • 2019-03-13
      • 1970-01-01
      • 2019-09-18
      • 2018-12-01
      • 2022-11-24
      • 2021-11-04
      相关资源
      最近更新 更多