How to call GET in +page.server.ts route from another route #6686
-
I currently have a structure like this:
Now I would like to get data from endpoint "routeA" into page from "routeB". Calling routeA's GET through fetch from routeB, but the result is not json, but the full HTML page instead, even though I am adding the following headers to fetch, like so:
Any help much appreciated |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Actually, you don't have an endpoint at routeA, endpoints are written in // routeA/page.js | page.server.js
export function load() {
return { myData }
} // routeA/page.svelte
<script>
export let data;
console.log(data.myData)
</script> // routeB/page.svelte
<script>
export let data;
console.log(data.myData)
</script> |
Beta Was this translation helpful? Give feedback.
-
You have a few options:
|
Beta Was this translation helpful? Give feedback.
You have a few options:
GET
endpoint in+server.ts
which you canfetch
from anywhere (likely inside+page.ts
and+layout.ts
).+layout.server.ts
and use a(group)
so both routes can inherit the data.