-
I'm coming from an Angular background and trying to see if SvelteKit is a good fit for future projects. Right now, I'm struggling with the nested layouts, where a routed component should be rendered inside another component. I've added a Stackblitz of this behaviour in Angular: https://stackblitz.com/edit/angular-ivy-tu3bj7. The Routes
I would like to use this behaviour in SvelteKit, but I'm having a hard time getting it to work. I'd thought I could use a What would be the correct 'SvelteKit' way of doing this? Create a standalone endpoint and calling that endpoint (with parameter) in the load function of the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I think I've found a working solution, not sure if it's the best solution, but it seems to work. I've created a My routes folder now looks as follows (maybe handy for anyone that has the same usecase)
|
Beta Was this translation helpful? Give feedback.
I think I've found a working solution, not sure if it's the best solution, but it seems to work.
I've created a
__layout.svelte
in the/todos/[id]
folder. In there, in theload
function, I call a standalone endpoint (created as/api/todos/[id].json.ts
which will take care of fetching the todo by ID. In the__layout.svelte
component, I render a Todo component where the todo is passed as a prop. THe last element in the__layout.svelte
is a<slot>
which will take care of rendering the Edit component.My routes folder now looks as follows (maybe handy for anyone that has the same usecase)