Skip to main content
Svelte基础
介绍
响应
属性Props
逻辑表达式
事件
绑定
Classes和样式
动作Actions
Transitions
Advanced Svelte
Advanced reactivity
Reusing content
Motion
Advanced bindings
Advanced transitions
Context API
Special elements
<script module>
Next steps
Basic SvelteKit
Introduction
Routing
Loading data
Headers and 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>