Prefix route of child pages with the UID of a single

I'm working on a @nuxt/prismic project with the Slice Machine.

I have a blog roll page which I want to live at /blog. I'd then like to have all blog posts at /blog/:uid.

I've set up my blog roll page as a Single Type called blog.

I've then created a Repeatable Type for the posts called blog_post.

This is my nuxt.config.js

'apiOptions': {
  'routes': [
    {
      'type': 'blog_post',
      'path': '/blog-post/:uid'
    },
    {
      'type': 'page',
      'path': '/:uid'
    }
  ]
}

I have a folder structure to match, and everything works. If I go to /blog I get the blog roll and if I go to /blog-post/some-post I get a blog post.

The issue is that I would like to have my blog posts retrievable from /blog/some-post. If I update my nuxt.config.js to...

'apiOptions': {
  'routes': [
    {
      'type': 'blog_post',
      'path': '/blog/:uid'
    },
    {
      'type': 'page',
      'path': '/:uid'
    }
  ]
}

...I can get to the blog roll but no the individual blog pages. Is this possible to achieve with a nuxt.config.js I am not aware of?

Hi Sel,

Welcome to the community! I'll be happy to help.

Can you share with me your folder structure of your project?

Thanks.

Screenshot 2020-10-26 at 14.59.17

Hi @Phil – thanks for responding.

I've actually gotten this to work now with the above folder structure and the default route resolver (rewired is the name of the blog).

As far as I can tell it's all working. The only strange side effect is that any blog post can be reached via the following URL, but it's a minor issue to be fair:

/rewired/any-category-not-even-the-one-attached-to-the-post/some-post

Are you providing the category through a content relationship in the blog post article?

Yes, I believe so...

In that case your route for your blog post route should look something like:

{
  type: 'blog_post',
  path: '/rewired/:category/:uid',
  resolvers: {
    category: 'category' // id of the content relationship in the blog_post custom type
  }
}
1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

This issue has been closed as it has been fixed, Flag if it is not the case for you to reopen.