首页 > 解决方案 > Nuxt 路由器,比 nuxt-child 更深入

问题描述

我正在使用 Nuxt Child 组件,但也想更深地链接到孩子。

我认为这最能说明问题。

example.com/cars               <-- cars.vue (has nuxt-child)
example.com/cars/bmw/          <-- cars/_maker.vue (this is the child)
example.com/cars/ford/         <-- cars/_maker.vue (this is the child)
example.com/cars/bmw/i3        <-- cars/_maker/type.vue (shows wrong template)
example.com/cars/ford/mustang  <-- cars/_maker/type.vue (shows wrong template)

_type.vue不渲染,而是使用_maker.vue模板。

我没有扩展路由设置,它完全脱离了目录结构路由。

如何获取使用模板/i3/mustang路径?type.vue

我想我可以通过不使用 Nuxt-Child 并做类似的事情来做到这一点,但我失去了良好的 Nuxt-Child 行为。

example.com/cars               <-- cars/index.vue
example.com/cars/bmw/          <-- cars/_maker/index.vue
example.com/cars/bmw/i3        <-- cars/_maker/_type.vue

标签: vue.jsroutingvue-routernuxt.js

解决方案


尝试在pages这样的文件夹上设置结构。

pages/
--| _cars/
-----| _maker/
--------| _type.vue
--------| index.vue
-----| _maker.vue
-----| index.vue
--| _cars.vue
--| index.vue

只需添加<nuxt-child/>in _cars.vue,如果不需要,则_maker.vue删除_type.vue文件。index.vue.


推荐阅读