Replies: 4 comments 2 replies
-
Yes! you can use SvelteHook that export from Or...Did you get any problems in SvelteKit? |
Beta Was this translation helpful? Give feedback.
-
I am trying to use alova with SvelteKit (not Svelte). The YouTube vid promoting it, as well as the website, indicates is support SSR, which would indicate it is possible to run server side with SvelteKit. SvelteKit 1 uses directory based routing (similar to Next.JS), and any route would typically have at least 2 pages:
A typical +page.js uses an extend web standard fetch (that runs in node.js too, i.e. server side first). Either +page.js file needs to "return data" object which is then accessible in the +page.svelte file. Example: export const load = async ({ fetch, event, setHeaders }) => { ...Note the 'data' from the API call must be returned. Then in +page.svelte, you'd have a script tag at the top that would make the data object available in the rest of the page, something like: ---- +page.svelte ----- <script> export let data; </script>My Homepage data: {JSON.stringify(data), null, 2} ---- +page.svelte ----- ...basically anything in braces lets you access the data object or other javascript you've written in the script tags. I followed your basic svelte example listed above, but can not figure out where to return the data. Each place I try it results in an error, which means the data from the API call is never available in the UI building file. I take it you aren't familiar with SvelteKit, but perhaps I've given enough data that you might have an idea how to covert the code example referenced in your above link into a function the in the end will 'return data'? |
Beta Was this translation helpful? Give feedback.
-
Incidentally, I did just try it in a new route, with no +page.js files, so just a +page.svelte file with your exact code (except with the API url replaced to something valid), and that doesn't work either. Vite console error: |
Beta Was this translation helpful? Give feedback.
-
@trulycool Thanks for your post, which let me realized that alova is incomplete in SSR. |
Beta Was this translation helpful? Give feedback.
-
Hi, does this package work with latest SvelteKit?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions