Skip to content

docs: How to wrap useAsyncData for SSR aware code (seo meta tags) #466

Open
@yllaw

Description

@yllaw

📚 Is your documentation request related to a problem?

I want to set meta tags server side for the web build.

The doc mentions to wrap useAsyncData for SSR aware code.

It is unclear how a implementation for such a wrapper function would look like.

🔍 Where should you find it?

https://ionic.nuxtjs.org/cookbook/web-and-device#a-single-codebase

ℹ️ Additional context

Our current workaround for SSR to set meta tags from asynchronous data on a nuxt/ionic web server is to

  1. Wrap useSeoMeta & useServerSeoMeta like so:
useIonMeta.ts

export function useIonMeta(seoInput: UseSeoMetaInput) {
  useServerSeoMeta(seoInput);

  onIonViewWillEnter(() => {
    useSeoMeta(seoInput);
  });
}
  1. Query async data and set tags in App.vue
App.vue

const { data } = await useFetch(`https://gorest.co.in/public/v2/users`);

  useIonMeta({
    title: () => data.value?.name,
    // more meta tags e.g. description, ogImageUrl, etc
  });

I would be more than happy to modify the docs and create a PR.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions