How to correctly use useRequestUrl
on a Nuxt module to prevent localhost
being returned?
#27393
Replies: 1 comment
-
I'm trying to understand how to solve this myself, but I'm not able to understand where to correctly set the caching options and how to access Nitro configuration from within a module. According to Nuxt docs (bold text is mine):
I'm not exactly sure about how and where this Some ideas or help are highly appreciated :) |
Beta Was this translation helpful? Give feedback.
-
I'm currently using the
useRequestUrl
composable in my "Nuxt Social Share" module to retrieve the current URL to be used by the provided components, namely social share buttons.The repository of this module is here https://github.com/stefanobartoletti/nuxt-social-share
While the exact point where
useRequestUrl
is this one https://github.com/stefanobartoletti/nuxt-social-share/blob/03a0f125fc62f1b333f772a126d8182d3036aade/src/runtime/useSocialShare.ts#L22I noticed that there are some situations where on deployed production sites, the URL used as retrieved from the composable is
localhost
, instead of the current page URL.According to the docs here https://nuxt.com/docs/api/composables/use-request-url this is a known behavior, and it is caused by Nitro caching.
I'd like to solve it on the module itself, without having to use specific configurations on the projects where the module itself is used, but I'm not really sure what is the best way to do so.
Can somebody provide some help or guidance?
Am I even using the best tool to accomplish the task? I just need the current URL, is
useRequestUrl
my best choice or do I have something else better sited for the situation?Thanks
EDIT:
In example, this is happening here https://nuxt-storyblok-starter.netlify.app/blog/article-8/, but only if this URL is accessed directly. If navigating from another page in the site, the correct URL is used in the social share buttons.
An issue with some more details has been opened here stefanobartoletti/nuxt-social-share#177
Beta Was this translation helpful? Give feedback.
All reactions