I am trying to build a simple blog with Svelte and Strapi v4 as backend. I have 2 pages : list of all posts page (no problem here) and the post page (problem here). For the list of posts, I manage to fetch my datas from Strapi using onMount. Works fine.
<script>
import { onMount } from "svelte";
let posts = []
onMount(async() => {
const response = await fetch('http://localhost:1337/api/blogs')
posts = await response.json()
}) //etc...
The link to go to the specific post page [id].svelte works :
<p class="link"><a href={`/blog/${post.id}`}>En savoir plus >>></a></p>
But I get then an error. I don't manage to tell Svelte : fetch this specific id datas in the [id].svelte page. Using the below code in [id].svelte does not work, I get a 404 in the console.
<script>
import { page } from '$app/stores';
console.log(page)
I also tried with this method with no success :
<script context="module">
export async function load(context = useContext(contextValue)) {
console.log(context);
I am blocked and don't know how to move forward. Getting also lost between SvelteKit, Svelte... Thanks for your great help.
Here is the file tree of the route :
I am also using svelte-routing in my App.svelte file. I use this below code trying to tell Svelte to find my [id] page. But I always get a return saying the page is not found on the server...
<!-- App.svelte -->
<script>
import { Router, Route } from "svelte-routing";
import Index from "./App.svelte";
import id from "./blog/[id].svelte";
export let url = "";
</script>
<Router url="{url}">
<Route path="blog/:id" let:params>
<posteid id="{params.id}" /></Route>
<Route path="/" component="{Index}" />
</Router>`
