Multi-level linkResolver

Hey,

I’m building a website for a client using Prismic and Gridsome (VueJS). I’m trying to create the following url structure: https://domain.com/parent-page/child-page

The child page has a Content Relationship field were the client can select the desired parent page. Now, I’d like to retrieve this parent page in the linkResolver so I can generate a dynamic url structure but I can’t seem to access the child page’s data in the linkResolver.

Does anyone has any idea how to do this?

Thanks

Hey Christian,

Welcome to the community!

We are trying to reproduce this, but I think the issue is because you’re using GraphQL the document data isn’t available in the link resolver. Although I could be wrong so I’m going to verify this and someone in the team will get back to you.

Thanks.

Hey Christian!

Phil is right. The link resolver doesn’t have access to the full document. It takes the metadata from a link in order to redirect to the correct page.

The child documents in your repository need to have Content relationship fields so they can reference their parent Pages.

@Phil it’s true that I’m using GraphQL to fetch all the page’s data. So you’re saying that I need to query my data a different way in order to make it work?

@paulina.gavilan the child documents do have Content Relationship fields actually. The repo for this client’s website is on an other account. If it helps I can send you the repo url where I’m trying to implement this?

Hey,

So I checked this. It works as long as you pass the full document to the link resolver (Not just the meta data) and you make sure you query the content relationship with at least the UID of the linked document.

Then you can construct a route like:

if (doc.type === 'page') { {
  return `/${doc.relationlink._meta.uid}/${doc._meta.uid}`
}