Skip to main content
Svelte基础
介绍
响应
属性Props
逻辑表达式
事件
绑定
Classes和样式
动作Actions
转场
Svelte高阶
响应式进阶
内容复用
动画
高级绑定
高级转场
上下文API
特殊元素
脚本模块
接下来
SvelteKit基础
介绍
路由
加载数据
Headers和cookies
Shared modules
Forms
API routes
$app/state
Errors and redirects
Advanced SvelteKit
Hooks
Page options
Link options
Advanced routing
Advanced loading
Environment variables
Conclusion

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.

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.

If you instead want to ensure that a trailing slash is always present, you can specify the trailingSlash option accordingly:

src/routes/always/+page.server
export const trailingSlash = 'always';

To accommodate both cases (this is not recommended!), use 'ignore':

src/routes/ignore/+page.server
export const trailingSlash = 'ignore';

The default value is 'never'.

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.

Edit this page on GitHub

previous next
1
2
<h1>trailingSlash</h1>