Replies: 5 comments 11 replies
-
+1 to anything in this area to make it more clear. I remember this was an area I struggled with when first getting started with Astro. Every time I pick up a different Astro project I find I need to re-learn these bits as well because they aren't 100% clear. Probably not in the scope of this, but having a way to make relative links more easily useable would be a win. I often see we suggest to people to use a full URL with a beginning slash because this area is difficult to explain and troubleshoot. This is honestly more of an issue with HTML links not being the same as file system links, but any way that Astro could make this easier for end users would be appreciated. |
Beta Was this translation helpful? Give feedback.
-
Linking a helpful guide to different deployment platforms: https://github.com/slorber/trailing-slash-guide Noting also that Starlight uses |
Beta Was this translation helpful? Give feedback.
-
From the PR: withastro/astro#11922 My initial thought is that pushing @bluwy said in reply:
Which web server doesn't allow this? I just tested with |
Beta Was this translation helpful? Give feedback.
-
Proposed default: trailingSlash: {
page: 'always',
endpoint: 'ignore'
} trailingSlash: 'never' // shortcut for..
trailingSlash: {
page: 'never',
endpoint: 'never'
} |
Beta Was this translation helpful? Give feedback.
-
I also think the behavior of |
Beta Was this translation helpful? Give feedback.
-
Body
Summary
Make
build.format
default value as"preserve"
and mergebuild.format
intotrailingSlash
.Background & Motivation
build.format
andtrailingSlash
are closely related. The way you build your pages (as files or directories) affect whether you need a trailing slash to access them or not.file.html
can only be accessed fromexample.com/file
dir/index.html
can only be accessed fromexample.com/dir/
The slashes are important as they affect how relative links are resolved on the webpage. You can't force
file.html
to be accessed fromexample.com/file/
for example without breaking relative links.Tricky workaround
Technically above can be kinda solved if you generate relative links with the anticipation of accessing from
example.com/file/
, however it can go wrong in, e.g. SSG, where deployment platforms may not allow you to accessfile.html
this way in the first place, you need SSR (as a custom server) to help with this.We try to avoid users hitting this footgun by suggesting a pair of
build.format
andtrailingSlash
configs: https://docs.astro.build/en/reference/configuration-reference/#effect-on-astrourl. The sour thing however is that our default options for both are already conflicting.Goals
Example (proposed changes)
trailingSlash: 'always'
the default. This reflects thebuild.format: 'preserve'
existing default.build.format
intotrailingSlash
, keeping the existing enums oftrailingSlash
build.format: 'directory'
, settrailingSlash: 'always'
build.format: 'file'
, settrailingSlash: 'never'
build.format: 'preserve'
, settrailingSlash: 'ignore'
build.format
completely but it'll be marked deprecated. We should warn in runtime if that option is used. And the old behaviour needs to be kept but no longer tested (?).EDIT: Updated proposed changes to have
trailingSlash: 'always'
as default.Beta Was this translation helpful? Give feedback.
All reactions