Getting Sveltekit to display some data from Strapi via API #9684
Replies: 4 comments 9 replies
-
I'm not sure but I think the error might be in return { props: { blogs: info.data } }
// not `res.data` |
Beta Was this translation helpful? Give feedback.
-
thats awesome! Progress but this is what I get versus the posts when I add one more into strapi it shows up, so the undefined are exactly like the posts I have on the cms |
Beta Was this translation helpful? Give feedback.
-
Additional console logs and errors: here is one from Chrome. I logged out 'data' on the page.svelte and I can now see the data coming in: not sure why it wont print? |
Beta Was this translation helpful? Give feedback.
-
Hello again. Thought to pick this up from here versus making a new thread. My main new challenge now is setting up a system where the user clicks on the blog item and then they see a bigger page with the full article. I know this is a slug system and I have made a route called: '/news/[slug]' and in there I have 2 files, a page.svelte and a page.server.ts. I copy pasted the working API call code into the new page.ts but not too sure how to bring all the data in without using a for each loop. totally new to dynamic routes. I have shower created a slug item on the strapi side. The new server.ts code is: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello all! I do hope you will help me with this issue I am facing.
So I have a web app built on Sveltekit. Here I intend to pull data from strapi for a blog as well as other information. I have made a route called news and a nested route called posts which is my API endpoint. Here in '/news/posts' I check with Postman and the demo data I have there flows in well:

The code that did that in the +server.ts files is:
` export const GET = async ({ request }) => {
const res = await fetch('https://cms.nafuna.tv/api/blogs')
const info = await res.json()
}`
so now I wanted to get the data into the main +page.svelte file. I have made a +page.server.ts to load the data from the endpoint:
export async function load({ fetch }) { const res = await fetch('/news/posts') const info = await res.json() return { props: { blogs: info.data } }; }
My main issue happens when I am trying to use that in the +page.svelte whose code looks like:
`<script lang="ts">
import type { PageData } from './$types';
{post.Title}
{/each} ` the above won't display the posts coming from API. What am I missing? I'm pretty new to Sveltekit and have been learning Javascript for under 3 months so there maybe things that I know I missed. Here is a screenshot side by side so you can better see:Kind regards!
Beta Was this translation helpful? Give feedback.
All reactions