Nuxt.js: Unexpected behavior with dynamic nested routes

Created on 5 Dec 2017  路  5Comments  路  Source: nuxt/nuxt.js

My intention was to create those routes:

/blog/:category/:subcategory/:postSlug
/blog/:category/:subcategory
/blog/:category
/blog

My folder structure looks like this:

folder-struct

Followed these docs: https://nuxtjs.org/guide/routing#dynamic-nested-routes
Paid attention to the tag, looking at these docs: https://nuxtjs.org/api/components-nuxt-child/

Expected behavior:
/blog shows posts
/blog/:category shows posts of a category
/blog/:category/:subcategory shows posts of a subcategory
/blog/:category/:subcategory/:postSlug shows a post

Actual behavior:
/blog shows posts (content in blog/index.vue)
/blog/:category shows posts of a category (content in blog/_categorySlug.vue)
/blog/:category/:subcategory
shows posts of a category (content in blog/_categorySlug.vue)
shows posts of a subcategory (content in blog/_categorySlug/_subCategorySlug.vue)
shows content inside blog/_categorySlug/_subCategorySlug/index.vue

/blog/:category/:subcategory/:postSlug
shows posts of a category (content in blog/_categorySlug.vue)
posts of a subcategory (content in blog/_categorySlug/_subCategorySlug.vue)
content inside blog/_categorySlug/_subCategorySlug/_postSlug.vue

Screenshot when accessed /blog/cat/sub/post
Shows posts of a category, subcategory and in the end shows the post title (there's only a title saying "Post page" in _postSlug.vue)
post-page

Should it really work like this?

This question is available on Nuxt.js community (#c2031)
question

Most helpful comment

Following these steps and removing the original files _categorySlug.vue and _subCategorySlug.vue solved my problem. The use of nuxt-child tag was not necessary.

Thanks a lot!

It might be interesting to add to these docs https://nuxtjs.org/guide/routing#dynamic-nested-routes an additional example for this expected behavior.

All 5 comments

If you don't want subpages contains content of parent, you can just remove sub-dir/index.vue or nuxt-child in it, then it will only show the content of itself page.

Removing the index.vue files did not change the behavior. The folder structure now looks like this:

blog-folder-struct

When I remove the nuxt-child tag, always the parent _categorySlug.vue is rendered, can't access subCategorySlug nor postSlug page components.

Try moving:

  1. _categorySlug.vue to blog/_categorySlug/index.vue
  2. _subCategorySlug.vue to blog/_categorySlug/_subCategorySlue/index.vue

Following these steps and removing the original files _categorySlug.vue and _subCategorySlug.vue solved my problem. The use of nuxt-child tag was not necessary.

Thanks a lot!

It might be interesting to add to these docs https://nuxtjs.org/guide/routing#dynamic-nested-routes an additional example for this expected behavior.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jaredreich picture jaredreich  路  3Comments

uptownhr picture uptownhr  路  3Comments

mikekidder picture mikekidder  路  3Comments

VincentLoy picture VincentLoy  路  3Comments

vadimsg picture vadimsg  路  3Comments