两个 URL(如 /foo
和 /foo/
)可能看起来相同,但实际上不同。像 ./bar
这样的相对 URL 在第一种情况下将解析为 /bar
,在第二种情况下解析为 /foo/bar
,搜索引擎会将它们视为单独的条目,从而损害你的 SEO。
¥Two URLs like /foo
and /foo/
might look the same, but they’re actually different. A relative URL like ./bar
will resolve to /bar
in the first case and /foo/bar
in the second, and search engines will treat them as separate entries, harming your SEO.
简而言之,对尾部斜杠过于宽松不是一个好主意。默认情况下,SvelteKit 会删除尾随斜杠,这意味着对 /foo/
的请求将导致重定向到 /foo
。
¥In short, being loosey-goosey about trailing slashes is a bad idea. By default, SvelteKit strips trailing slashes, meaning that a request for /foo/
will result in a redirect to /foo
.
如果你想要确保尾部斜杠始终存在,则可以相应地指定 trailingSlash
选项:
¥If you instead want to ensure that a trailing slash is always present, you can specify the trailingSlash
option accordingly:
export const trailingSlash = 'always';
为了适应这两种情况(不推荐!),请使用 'ignore'
:
¥To accommodate both cases (this is not recommended!), use 'ignore'
:
export const trailingSlash = 'ignore';
默认值为 'never'
。
¥The default value is 'never'
.
是否应用尾部斜杠会影响预渲染。像 /always/
这样的 URL 将作为 always/index.html
保存到磁盘,而像 /never
这样的 URL 将保存为 never.html
。
¥Whether or not trailing slashes are applied affects prerendering. A URL like /always/
will be saved to disk as always/index.html
whereas a URL like /never
will be saved as never.html
.
<h1>trailingSlash</h1>