Skip to content

file based layout reset #1376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TheComputerM opened this issue May 7, 2021 · 4 comments
Closed

file based layout reset #1376

TheComputerM opened this issue May 7, 2021 · 4 comments

Comments

@TheComputerM
Copy link

Is your feature request related to a problem? Please describe.
Here is my file structure

- folder
  - 0.svelte
  - 1.svelte
  - special.svelte

I want 0.svelte and 1.svelte to inherit the layout but not special.svelte.

Describe the solution you'd like

<script context="module">
export let inheritLayout = false;
<script>
@didier
Copy link

didier commented May 7, 2021

This can already be done by putting special in its own folder.

├─ routes/
│  ├─ special/
│  │  ├─ index.svelte
│  │  ├─ $layout.reset.svelte
│  ├─ 0.svelte
│  ├─ $layout.svelte
│  ├─ 1.svelte\

@TheComputerM
Copy link
Author

Nice, but can you suggest any method by which I can do the same thing but with the root index.svelte.

- index.svelte
- section1
    - page1.svelte
- section2
    - page2.svelte

section 1 and 2 should have same layout but not index.svelte.

@didier
Copy link

didier commented May 7, 2021

@TheComputerM I'd suggest making a layout component (SectionLayout.svelte), defining your layout there, and importing it in the __layout.svelte of section1 and section2:

src/
├── lib/
│   └── components/
│       └── SectionLayout.svelte
└── routes/
    ├── index.svelte
    ├── section-1/
    │   ├── index.svelte
    │   └── __layout.svelte
    └── section-2/
        ├── index.svelte
        └── __layout.svelte

I'll admit—it isn't ideal, but it definitely does the job.

EDIT: Changed $layout to __layout, as per @sveltejs/kit@^1.0.0-next.102

@intrikate
Copy link

intrikate commented May 7, 2021

Given the structure above, layouts for section-1 and section-2 will always mutually reset. This may be a factor if you depend on layout preservation.

In a similar #1110, it was proposed to adjust one layout from different routes using context. That approach offers potentially unlimited control over what is done and how, and should, in theory, allow shared layouts to remain actually shared. Please note that in practice the concept of ‘shared’ is currently shaky (see #1214).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants