Using both Route Resolver and Link Resolver with next.js for previews

Route Resolver - Documentation - Prismic documentation specifically says that it's possible to use both route resolver and link resolver, where link resolver gets the priority over the route resolver.

If your project includes both a link resolver and a route resolver, the link resolver will take priority. Where the link resolver returns null, the route resolver will be used.

But, I didn't find any documentation on where to create the linkResolver. I have tried below ways, and both didn't work.

  1. Define a new file called ``src/linkResolver.ts and export the linkResolver function as the default export. (DIDN'T WORK)
// src/linkResolver.ts
function linkResolver(doc: prismic.PrismicDocument) {
  if (doc.type === 'author') {
    return `/about?author=${doc.uid}`;
  }
  return null;
}
export default linkResolver;
  1. Define and export linkResolver variable in already existing src/prismicio.ts (DIDN'T WORK)
// src/prismicio.ts
export function linkResolver(doc: prismic.PrismicDocument) {
  if (doc.type === 'author') {
    return `/about?author=${doc.uid}`;
  }
  return null;
}

How should I define the linkResolver which I can be used to preview documents?

Hi @umesh,

Welcome to the community :slight_smile:

You can have previews using just the route resolver. Is there anything specific you're trying to do with the link resolver, and can you share what errors you're seeing when it doesn't work?

@Ezekiel with route resolver, I didn't find a way to pass the uid to a query parameter. (same as the example I added in the question).
i.e. with route resolver, I can do => '/about/:uid'
but I can't do (didn't find a way) => '/about?author=:uid'

I don't see any error, but prismic preview only works for the routes in the route resolver, Any path I return from the linkResolver doesn't work.

Hi @umesh,

I see what you mean. I believe either of your implementations should have worked (in a new file or in prismicio.ts). Just to clarify, you're able to get your content published and accessed properly, it's only a problem to create previews?

When you say it didn't work, can you elaborate on which part wasn't working? was the preview not displaying the proper page? Redirecting somewhere else? Not showing anything?

Feel free to show me what you're seeing with a Jam recording or screenshots :slight_smile: