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

通常,页面会继承其上方的每个布局,这意味着 src/routes/a/b/c/+page.svelte 继承了四个布局:

¥Ordinarily, a page inherits every layout above it, meaning that src/routes/a/b/c/+page.svelte inherits four layouts:

  • src/routes/+layout.svelte

  • src/routes/a/+layout.svelte

  • src/routes/a/b/+layout.svelte

  • src/routes/a/b/c/+layout.svelte

有时,打破当前布局层次结构很有用。我们可以通过将 @ 符号后跟父段的名称添加到 ‘reset’ 来实现这一点 — 例如,+page@b.svelte 会将 /a/b/c 放在 src/routes/a/b/+layout.svelte 内,而 +page@a.svelte 会将其放在 src/routes/a/+layout.svelte 内。

¥Occasionally, it’s useful to break out of the current layout hierarchy. We can do that by adding the @ sign followed by the name of the parent segment to ‘reset’ to — for example +page@b.svelte would put /a/b/c inside src/routes/a/b/+layout.svelte, while +page@a.svelte would put it inside src/routes/a/+layout.svelte.

让我们将其重置为根布局,将其重命名为 +page@.svelte

¥Let’s reset it all the way to the root layout, by renaming it to +page@.svelte.

根布局适用于应用的每个页面,你无法脱离它。

¥[!NOTE] The root layout applies to every page of your app, you cannot break out of it.

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