Skip to main content
基本 Svelte
介绍
反应性
属性
逻辑
事件
绑定
类和样式
动作
转换
高级 Svelte
高级反应性
重用内容
运动
高级绑定
高级转换
上下文 API
特殊元素
<script module>
后续步骤
基本 SvelteKit
介绍
路由
加载数据
标题和 cookie
共享模块
表单
API 路由
$app/state
错误和重定向
高级 SvelteKit
钩子
页面选项
链接选项
高级路由
高级加载
环境变量
结论

要创建具有动态参数的路由,请使用方括号括住有效的变量名。例如,像 src/routes/blog/[slug]/+page.svelte 这样的文件将创建与 /blog/one/blog/two/blog/three 等匹配的路由。

¥To create routes with dynamic parameters, use square brackets around a valid variable name. For example, a file like src/routes/blog/[slug]/+page.svelte will create a route that matches /blog/one, /blog/two, /blog/three and so on.

让我们创建该文件:

¥Let’s create that file:

src/routes/blog/[slug]/+page
<h1>blog post</h1>

我们现在可以从 /blog 页面导航到单个博客文章。在下一章中,我们将了解如何加载其内容。

¥We can now navigate from the /blog page to individual blog posts. In the next chapter, we’ll see how to load their content.

多个路由参数可以出现在一个 URL 段中,只要它们之间至少有一个静态字符分隔即可:foo/[bar]x[baz] 是有效路由,其中 [bar][baz] 是动态参数。

¥[!NOTE] Multiple route parameters can appear within one URL segment, as long as they are separated by at least one static character: foo/[bar]x[baz] is a valid route where [bar] and [baz] are dynamic parameters.

上一页 下一页
1
2
<p>home</p>