Closed tobiasBora closed 1 month ago
Possible solutions are:
/static/admin/index.html
/src/routes/admin/+server.ts
You can use custom template engines in server endpoints, such as LiquidJS.
If the index.html
file is just a template, and Svelte should be rendered inside it, use (groups)
https://kit.svelte.dev/docs/advanced-routing#advanced-layouts
+layout.svelte
and the related files./src/routes/(non-admin)
and /src/routes/(admin)/admin
directories.You can now use separate +layout.svelte
for each groups.
Thanks, but I can't find how this adress raised in the issue (I will try the second server.js based solution later today):
/static/admin/index.html
will not redirect the /admin
page to the /admin/index.html
leading to a 404 error. It might be possible to do this in production if we serve the static files from nginx or alike but not sure what is the correct way to do it to get it to work both in prod and while developping with npm run dev
app.html
is always used to wrap the layout content, and can't find how to get rid of thisI've understood why /static/admin/index.html
does not work. Thanks for the clarification.
Serving the index.html
file or a newly generated HTML using template engines (e.g. LiquidJS, Nunjucks) in the +server.ts
endpoint will definitely work. I am actually using it in a project.
If you can overhaul the project structure, I suggest the following:
└── src/
├── app.html - Generic as possible. Don't add anything here.
└── routes/
├── (admin)/
│ ├── admin
│ └── +layout.svelte - Use the group layout to add `<svelte:head>` etc.
└── (non-admin)/ - Put existing routes in this group.
├── about
├── profile
└── +layout.svelte - Use the group layout to add `<svelte:head>` etc.
Note that even with this approach, you cannot add Svelte page component directly under <body>
.
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
If you want to render a file actually verbatim, then a +server
route is how you probably should be doing it.
If you want to render a page without any wrapping layout other than what's present in your app.html
, then you need to make sure your top-level layout doesn't introduce any wrapping markup. The way to do this (while preserving shared layouts for other routes) is with layout groups, as mentioned above.
Describe the problem
I have a template index.html that I want to include verbatim at url
/admin
. But if I put its content in+page.svelte
, it gets wrapped by the content ofapp.html
and the root+layout
file. I tried to move it in/static/admin/index.html
, but then the issue is thatadmin/index.html
works, butadmin
alone gives an error 404.Describe the proposed solution
Maybe allow the user to define a file like
+layout@@.svelte
to inherit from nothing, not evenapp.html
or the root layout.Alternatives considered
No response
Importance
would make my life easier
Additional Information
No response