Using adapter-static and trailingSlash='always' in svelte.config.js doesn't work when using group layouts
Describe the bug
When:
- Using adapter-static
- and setting
trailingSlash: 'always'inside the adapter settings in svelte.config.js - and using group layouts
And:
- running
npm run build
Then:
- route pages are still generated as
/a.htmlinstead of the expected/a/index.html.- Using the screenshot above, the build generates
privacy.htmlandterms.htmlinstead ofprivacy/index.htmlandterms/index.html
- Using the screenshot above, the build generates
This is confusing because the adapter-static docs say that this should work.
To fix, you must add export const trailingSlash = 'always'; inside each +layout.ts file.
Reproduction
- Create a sample sveltekit project
- Add some group layouts with pages inside
- Configure it to use adapter static and set
trailingSlash = 'always'in the adapter config is described here: https://kit.svelte.dev/docs/adapter-static#usage - Run
npm run build - Notice the generated output in the build folder is of the format a.html instead of /a/index.html
Logs
No response
System Info
System:
OS: Linux 5.19 KDE neon 5.27 5.27
CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Memory: 3.44 GB / 15.38 GB
Container: Yes
Shell: 5.8 - /usr/bin/zsh
Binaries:
Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
npm: 8.5.5 - ~/.nvm/versions/node/v16.15.0/bin/npm
Browsers:
Chrome: 114.0.5735.133
npmPackages:
@sveltejs/adapter-auto: ^2.0.0 => 2.1.0
@sveltejs/adapter-static: ^2.0.2 => 2.0.2
@sveltejs/kit: ^1.5.0 => 1.20.0
svelte: ^3.54.0 => 3.59.1
vite: ^4.3.0 => 4.3.9
Severity
serious, but I can work around it
Additional Information
No response
Putting the trailingSlash in the adapter config was the old way of doing things, now it's handled per route. I went through the docs you mentioned in the Discord thread but I cannot find anywhere where it mentions the old way of doing things, could you point to the specific sentence or paragraph?
I was also a bit confused by this -- from the Note: in this section of the docs https://kit.svelte.dev/docs/adapter-static#usage
The "Note" section is ambiguous. It says you will need to set trailingSlash: 'always' but it doesn't say where to set it. I had assumed that it should be set in svelte.config.js because that's where the other adapter settings are specified. Also, does it need to be set in just the root layout or all layouts (esp group layouts)?
I recommend updating the Note section to explain that "you will need to set trailingSlash: 'always' in your layout to create /a/index.html instead." (see the addition of "in your layout").