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: domain.com/contentpage-one/contentpage-two.
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.
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:
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.
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:
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?
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.
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:
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.