How to reset a layout in svelte/kit with vite
Asked Answered
A

2

5

If I have a main layout "+layout.svelte" at /routes and then try to reset the layout at /routes/auth/login It is not working.

  • If the name is "+layout.svelte" the layout is embedding inside the main layout.
  • If the name is "[email protected]" it's not working.
  • If the name is "+layout.reset.svelte" its: Error: Files prefixed with + are reserved.

Because the default configuration of svelte/kit is vite. I think they changed it, but I don't know how to do it.

Only thing I can find in the docs about resetting layouts.

At: kit.svelte.dev/docs/advanced-routing#advanced-layouts-layout

Agreeable answered 30/8, 2022 at 11:57 Comment(3)
What do you mean by "not working"? Can you share the error messages?Serinaserine
[email protected]: Error: Files prefixed with + are reserved (saw src/routes/auth/[email protected]) The only way I get no Error is when I use the default "+layout.svelte" name, but then it's embedding into the root layout from /src/routes/+layout.svelteAgreeable
I answered the question in detail on this stackoverflow link https://mcmap.net/q/1750539/-make-child-nested-layout-not-inherit-parent-layoutPyongyang
B
9

Stuff has happened in the world since the accepted answer was posted. This is also true for Svelte/kit. Now there is something called (group) that looks like this:

src/routes/
│ (app)/
│ ├ dashboard/
│ ├ item/
│ └ +layout.svelte
│ (marketing)/
│ ├ about/
│ ├ testimonials/
│ └ +layout.svelte
├ admin/
└ +layout.svelte 

This lets you group layouts in directories that has its name wrapped in parenthesis (that don't affect the routing). Here a +layout.svelte file inside such a directory will add to the src/+layout.svelte file - this layout wraps all other layout files defined in grouped directories.

Once you wrap your head around it, it is very easy to use. Read more about it in the documentation for advanced routing / advanced layouts

Botch answered 8/12, 2022 at 11:24 Comment(3)
yep used it already, but thanks for your answerAgreeable
It felt wrong at first to nest nearly all routes under a directory just so that one route could be reset, but that feeling goes away eventually.Lianna
feel like it should be the opposite way...Kleptomania
G
3

you need to create login layout at routes as +layout-login.svelte and refer on login page as [email protected]

Glenda answered 31/8, 2022 at 10:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.