Generate automatic `<slot />` `+layout.svelte` when `+layout.ts` is present
See original GitHub issueDescribe the problem
Sometimes, I just want to create “side effects” from visiting a route:
// +layout.ts
import { crumbsStore } from '$lib/components/Breadcrumb';
import type { LayoutLoad } from './$types';
export const load: LayoutLoad = () => {
crumbsStore.addCrumb({ path: '/data-analytics/operations', name: 'Operations', enabled: true });
return {
pageTitle: 'Operations',
};
};
In this case, there doesn’t need to be any +layout.svelte
, because all I want to do is add my pageTitle
to the rolled-up data
object (which my root layout is listening to, setting the page’s Title) and add a breadcrumb to a store (which is how my Breadcrumb
component works). Right now, I have to create a +layout.svelte
with only <slot />
as the content, or nothing will be rendered on or under this route. That seems kind of silly.
Describe the proposed solution
When a +layout.ts
or a +layout.server.ts
exists but there isn’t any +layout.svelte
, Kit should just inject a default +layout.svelte
containing an empty slot.
Note: If we went this route, we’d have to make an update to how we’re generating types, as currently +layout.ts
and +layout.server.ts
don’t get their types generated if there’s no +layout.svelte
.
Alternatives considered
Just live with the extra files 🤷🏻
Importance
nice to have
Additional Information
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:25
- Comments:5 (2 by maintainers)
Also bumped into this issue, was confused why
LayoutLoad
wasn’t appearing inimport("./$types")
. Creating a+layout.svelte
with a<slot/>
workedRan into this while following the docs: https://kit.svelte.dev/docs/load#input-methods-parent and it was very annoying to find out what the hell was wrong because the docs list it as valid…