Dynamic routing issue

I have the following structure in my pages folder

- pages
-- _section
---- _category
------ _uid.vue
------ index.vue
---- index.vue

and the following routes:

{
	type: 'section',
	path: '/:uid'
},
{
	type: 'category',
	path: '/:section/:uid',
	resolvers: {
		section: 'section'
	}
},
{
	type: 'page',
	path: '/:section/:category?/:uid',
	resolvers: {
		section: 'category.section',
		category: 'category'
	}
}

As long as i keep content of type "page" in a strict section/category/page structure it all works great. But I want to be able to place content of type "page" in the root, below any section or any category. How do i achieve this? What if i make another content type and want to place this in any given root/section/category, how do i separate the new content type from "page"?

Hey, @tomfri, thanks for sharing your use case with us. I haven't tested a similar project structure myself, but I believe it is possible.

The first two paths don't seem like they would match what you need. Are you trying to build URLs for the Category and Section types as well?

You need to create the root path for the Page type; have you tried something like this?

{
	type: 'page',
	path: '/:uid'
},
{
	type: 'page',
	path: '/:section/:category?/:uid',
	resolvers: {
		section: 'category.section',
		category: 'category'
	}
}

Hi @Paulina !
Thank you so much for your positive response!

You are correct, I am trying to bild URL:s for the Category and Section types as well and they seem to disturb each other. The type part seems to be ignored when matching the route. When publishing a page below Section (/{Section}/page) the Category route is hit, how can this be?

I have tried what you suggest and I have also tried a question mark after "/:section?" which, as I understand, is the same...?

I found this post Nuxt with SM Routes - #3 by arcaneshawn which is kind of matching my issue and now I'm experimenting with hard coded Section to see if it works better.

I'm experimenting here, please let me know if you find a solution to my problems.

I'm going to try it out on my end with a sample project. It would help me a lot if you could share with me the following details so I can try and mimic your project as much as possible:

  • The URL of your repository
  • The JSON files of your Custom Types
  • At least one example of each URL that you want to accomplish. For example:
    • '/:uid' would be /about
    • '/:section/:uid' would be /our-company/about
    • '/:section/:category?/:uid', would be /products/our-brands/item

This thread has been closed due to inactivity. Flag to reopen.