-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useAsyncData example for static generation #81
Comments
Hello, have you found a solution yet? |
I think if you just use your composables in set |
@Intevel not sure if I understand it correctly, but would just using composables really change anything? I currently have
|
Do you want the content from the API to be in the static HTML or do you want the static page to fetch the data on load? |
@Intevel I want the content to be in the static HTML |
Then you remove the ssr property, and just call nuxi generate. This will pretender the routes |
@Intevel I don't think there is a third state of the ssr property. It's true by default https://nuxt.com/docs/api/configuration/nuxt-config/#ssr I've tried it with no success and I still see requests in the browser to directus |
Can you show me you're nuxi generate output? |
|
Okay @mklueh I will try something tomorrow and let you know then. |
@Intevel thanks I'd guess one could use something like this
But so far I had no success Edit: I've found this package https://www.npmjs.com/package/nuxt-full-static indicating that maybe it's not working out of the box, but on the other hand how is it working with normal REST calls to the backend then? |
Yes but nuxt-full-static was just a PoC, before Nuxt 3 has static support. I guess. |
@Intevel yes. But I don't understand it. What is the difference between rendering a static site from a REST API directly vs rendering using the Directus SDK that uses a REST API? |
The way you explain it there is no difference, but you want the content to be directly in the code. |
@Intevel Yes, and I think https:/nuxt/content works also that way if I'm not mistaken. I've seen this docs now https://nitro.unjs.io/config/#prerender and maybe the issue is related, because my /blog page has no link from / and the crawler does not pick it up that way. Need to investigate a bit later. |
@Intevel linking to the blog page did not change anything. Do you have any other ideas ? |
@Intevel ok got it now after trying a bit more! I've tested it again with ssr: true and useAsyncData and this seems to work nuxt.config.ts
blog.vue
|
@mklueh Do you think you can make a Pull Request to document this? |
@Intevel I can do that tomorrow likely |
@Intevel do you have any preference on where it should be added to the docs? I'm leaning towards "Setup" or "Options", rather than creating a new "Rendering" sub-page |
I've added it to the options.md page and created a pull request #96 |
Hi, I'm looking for some help in achieving the same thing - getting Directus content 'inlined' into the static site upon build. I'm using composables to query the API and I'm having some trouble implementing useAsyncContent in this context. Here is a typical composable as it is, which currently works (I'm cutting out the fields here to make it easier to read):
And here it is with my attempt to use useAsyncData:
But the above gives me 500/'undefined' errors. For what it's worth, here is how I use the composable on pages:
Any help here would be greatly appreciated. Thanks! |
How one would use directus API to generate a completely static site using Nuxt3? Simple html/js files that do not trigger backend requests.
I'm trying to implement the following:
But recent Nuxt 3 RC's (9 and 12) either fail to generate directly accessible SSR pages or mix their markup with the front page. Also I'm having trouble to prevent Directus API calls (which are unnecessary for a completely static website).
The text was updated successfully, but these errors were encountered: