Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Passing props via layout components #312

Closed
Rich-Harris opened this issue Jul 23, 2018 · 0 comments · Fixed by #313
Closed

Passing props via layout components #312

Rich-Harris opened this issue Jul 23, 2018 · 0 comments · Fixed by #313

Comments

@Rich-Harris
Copy link
Member

A minor annoyance with 0.15: if you're using a default layout component, it won't propagate data specified in custom layout components:

<!-- routes/_layout.html -->
<svelte:component
  this={child.component}
  {customThing}
  {child.props}
/>

<script>
  export default () {
    preload() {
      return { customThing: 'potato' };
    }
  };
</script>
<!-- routes/foo/index.html -->
<p>custom thing: {customThing}</p>

You might expect customThing to be passed down to /foo, since it appears to be the child component. But in fact, the child component is the default layout component, and we need to override it like so:

<!-- routes/foo/_layout.html -->
<svelte:component
  this={child.component}
  {customThing}
  {child.props}
/>

One way we could solve this is to remove any intermediate default layout components. In other words, child.component in the top-level layout component would be the routes/foo/index.html component. This would have the added benefit of simplifying Svelte's internal representation of the DOM.

Rich-Harris added a commit that referenced this issue Jul 23, 2018
Rich-Harris added a commit that referenced this issue Jul 23, 2018
Skip layout components where none is provided
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant