kit icon indicating copy to clipboard operation
kit copied to clipboard

Using adapter-static and trailingSlash='always' in svelte.config.js doesn't work when using group layouts

Open jedfonner opened this issue 2 years ago • 1 comments

Describe the bug

When:

  • Using adapter-static
  • and setting trailingSlash: 'always' inside the adapter settings in svelte.config.js
  • and using group layouts image

And:

  • running npm run build

Then:

  • route pages are still generated as /a.html instead of the expected /a/index.html .
    • Using the screenshot above, the build generates privacy.html and terms.html instead of privacy/index.html and terms/index.html

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

  1. Create a sample sveltekit project
  2. Add some group layouts with pages inside
  3. 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
  4. Run npm run build
  5. 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

jedfonner avatar Jun 24 '23 14:06 jedfonner

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?

khromov avatar Jun 24 '23 15:06 khromov

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

brittharr avatar Jun 26 '23 11:06 brittharr

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)?

image

jedfonner avatar Jun 27 '23 19:06 jedfonner

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").

jedfonner avatar Jun 27 '23 19:06 jedfonner