sveltejs / sapper

The next small thing in web development, powered by Svelte
https://sapper.svelte.dev
MIT License
7k stars 434 forks source link

Passing props to layouts #877

Open ramiroaisen opened 5 years ago

ramiroaisen commented 5 years ago

Is your feature request related to a problem? Please describe. It would be nice if we could pass properties from pages to layouts

Describe the solution you'd like The solution would be very simple, just expose an export let layoutProps en every component (it could be done into the module context script of the component

How important is this feature to you? I think this would be very usefull, instead of looking into the $page the child page can "tell" the layout how to behave

bikeshedder commented 4 years ago

I think this could be solved by a store inside the context of the layout. Currently this seams to be broken for SSR. See #917

alexdilley commented 4 years ago

The server-side context issue can be summarised as:

export n = 1;
const store = writable(0);
setContext(CTX_KEY, store);
$: $store = n;
// ...and then, in a child component...
const ctx = getContext(CTX_KEY);
<h1>{$ctx}</h1>
// => renders `<h1>0</h1>` (i.e. doesn't honour the change to store...until hydration)