Link resolving a parent/child relationship with one custom type

Hi there,

Using Nuxt.js, I am trying to get a parent/child page relationship to work using only one ‘contentpage’ custom-type. I am looking to create the following url:

To achieve this I added a ‘Parent page’ content-relationship field on the contentpage custom-type. So in the above scenario, the ‘contentpage-two’ page has ‘contentpage-one’ selected as its parent. However when using the ‘prismic-link’ component in Nuxt.js with the ‘Parent page’ content-relationship as field property, I don’t have access to the slug of the actual page (only of the parent page) in the link resolver.

It would be great if someone could help me achieve this relationship in a way that’s easy for clients to maintain and edit in Prismic.

Bonus: a ‘’ option would be pretty great!

Thanks in advance,

Hi Joep,

Welcome to the community!

Here’s one I built recently. Since you’re passing the whole document to the link resolver you have access to the document data, so you can construct the link resolver like so:

  if (doc.type === 'contentpage') {
    if (! {
      return `/${doc.uid}`
    } else {
      return ( ? `/${}/${doc.uid}` : `/${doc.uid}`)

This construction also runs a check to make sure the document data is there and for parent pages where the ‘parent_page’ content relationship is empty it returns the simple URL.

We have created a new Link Resolver which is only currently available for Slice Machine projects which will be able to handle grand parent relationships. Hopefully in the future we can roll this out for everyone. Until then this is the best way.

Let me know if you have any questions.


Hi Phil,

Thank you so much for your reply. I tried your code, and it makes sense.

However for some reason the linkresolver is not being called when I pass the whole page object into the prismic-link vue component (like Link. It does work when I only pass in the parent_page content relationship object within the page object. The page object of the child page looks like this:




            "text":"Child content pagee",



When I preview content from Prismic, the link resolver does resolve the correct link. Do you maybe have an idea why the link resolver is not called when passing in the whole page object?

Thanks a lot!

OK let’s look a bit more, can you share with me the code where you do your query and pass it to the prismic-link component? Maybe with a Github repo so I can check all your code.

Thank you for helping!
I pushed the code to:

Hey Joep,

So I figured it out. Thanks for sending your code to help.

When processing the link on your home page it’s a little different as you need to make sure you pass the page through the link resolver first, then pass this through the nuxt-link like shown below:

<nuxt-link :to="$prismic.linkResolver(page)">
  <prismic-rich-text :field="" />

I also noticed you did a check on the id in the link resolver, so for any future readers where the parent link is being returned with an undefined route, his different his check looks like this.

return ( ? `/${}/${doc.uid}` : `/${doc.uid}`)


This works perfectly! Thanks!

1 Like

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