prismic icon indicating copy to clipboard operation
prismic copied to clipboard

Any way to provide app context to link resolver for nuxt-i18n compat?

Open zrisher opened this issue 5 years ago • 1 comments

When writing the linkResolver function, we must provide our full understanding of our app's routing. This works fine in simple cases.

However, some of us use nuxt-i18n to manage language-aware routing, which does some complicated things like discovering routes, merging them with custom language-specific paths, and siloing routes by language code. We can provide it with a full list of the languages we support, the default, etc.

It can be time-consuming and error prone to have to duplicate the final routing logic of nuxt-i18n when writing our linkResolver function. It would be significantly easier if we had access to nuxt-i18n's helpers, which are provided to components via global mixins and as part of Nuxt's context.app.

I believe this is the same issue that was mentioned here: https://github.com/nuxt-community/prismic-module/issues/23

I'm not super familiar with any of these libraries yet, so please forgive my lack of understanding here. Does anyone have suggestions on how to accomplish this? Perhaps we could amend how Prismic Nuxt loads the linkResolver before passing it to Prismic Vue - if it provided the plugin file with access to context and then expected it to return a constructed linkResolver function which makes use of the helpers it pulled from context.app?

zrisher avatar Oct 23 '20 22:10 zrisher

Hey @zrisher, I'm really sorry for the delay, might have slipped through my notifications 🙏

I understand the issue here and this is a great feedback! I definitely agree that it's not convenient, error-prone, to maintain a routing strategy for Prismic separated from the Nuxt i18n one and I'm afraid there's currently no way to overcome that.

As pointed out in https://github.com/nuxt-community/prismic-module/issues/23#issuecomment-487290764 you should have access to doc.lang in order to perform routing in your link resolver. An alternative method to resolving links if through the apiOptions.routes object, more info about it here: https://prismic.nuxtjs.org/configuration#new-routes-resolver

We are planning to work on a major version (v. 2) of this module in Q1 2021 next year and I'll definitely look for a way to grant access to Nuxt context inside the link resolver and HTML serializer :)

lihbr avatar Nov 12 '20 11:11 lihbr