Skip to content

Commit

Permalink
[docs] clarify page components (#3767)
Browse files Browse the repository at this point in the history
* [docs] clarify page components

* tweaks

* add a clarifying comma

Co-authored-by: Rich Harris <hello@rich-harris.dev>
  • Loading branch information
benmccann and Rich-Harris committed Feb 15, 2022
1 parent e2d4715 commit cff94c1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions documentation/docs/02-layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ So far, we've treated pages as entirely standalone components — upon navigatio

But in many apps, there are elements that should be visible on _every_ page, such as top-level navigation or a footer. Instead of repeating them in every page, we can use _layout_ components.

To create a layout component that applies to every page, make a file called `src/routes/__layout.svelte`. The default layout component (the one that SvelteKit uses if you don't bring your own) looks like this...
To create a layout that applies to every page, make a file called `src/routes/__layout.svelte`. The default layout (the one that SvelteKit uses if you don't bring your own) looks like this...

```html
<slot></slot>
Expand Down Expand Up @@ -70,7 +70,7 @@ Layout resets are otherwise identical to normal layout components.

### Error pages

If a page fails to load (see [Loading](/docs/loading)), SvelteKit will render an error page. You can customise this page by creating `__error.svelte` components alongside your layout and page components.
If a page fails to load (see [Loading](/docs/loading)), SvelteKit will render an error page. You can customise this page by creating `__error.svelte` components alongside your layouts and pages.

For example, if `src/routes/settings/notifications/index.svelte` failed to load, SvelteKit would render `src/routes/settings/notifications/__error.svelte` in the same layout, if it existed. If not, it would render `src/routes/settings/__error.svelte` in the parent layout, or `src/routes/__error.svelte` in the root layout.

Expand Down Expand Up @@ -108,6 +108,6 @@ If an error component has a [`load`](/docs/loading) function, it will be called
<h1>{title}</h1>
```

> Layout components also have access to `error` and `status` via the [page store](/docs/modules#$app-stores)
> Layouts also have access to `error` and `status` via the [page store](/docs/modules#$app-stores)
>
> Server-side stack traces will be removed from `error` in production, to avoid exposing privileged information to users.
4 changes: 2 additions & 2 deletions documentation/docs/03-loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ If the page you're loading has an endpoint, the data returned from it is accessi

#### stuff

`stuff` is passed from layout components to child layouts and page components and can be filled with anything else you need to make available. For the root `__layout.svelte` component, it is equal to `{}`, but if that component's `load` function returns an object with a `stuff` property, it will be available to subsequent `load` functions.
`stuff` is passed from layouts to descendant layouts and pages, and can be filled with anything else you need to make available. For the root `__layout.svelte` component, it is equal to `{}`, but if that component's `load` function returns an object with a `stuff` property, it will be available to subsequent `load` functions.

### Output

Expand All @@ -151,7 +151,7 @@ The `redirect` string should be a [properly encoded](https://developer.mozilla.o

To cause pages to be cached, return a `number` describing the page's max age in seconds. The resulting cache header will include `private` if user data was involved in rendering the page (either via `session`, or because a credentialed `fetch` was made in a `load` function), but otherwise will include `public` so that it can be cached by CDNs.

This only applies to page components, _not_ layout components.
This only applies to pages, _not_ layouts.

#### props

Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/11-page-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Page options

By default, SvelteKit will render any component first on the server and send it to the client as HTML. It will then render the component again in the browser to make it interactive in a process called **hydration**. For this reason, you need to ensure that components can run in both places. SvelteKit will then initialise a [**router**](/docs/routing) that takes over subsequent navigations.

You can control each of these on a per-app or per-page basis. Note that each of the per-page settings use [`context="module"`](https://svelte.dev/docs#component-format-script-context-module), and only apply to page components, _not_ [layout](/docs/layouts) components.
You can control each of these on a per-app or per-page basis. Note that each of the per-page settings use [`context="module"`](https://svelte.dev/docs#component-format-script-context-module), and only apply to pages, _not_ [layouts](/docs/layouts).

If both are specified, per-page settings override per-app settings in case of conflicts.

Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/80-migrating.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Any files you previously imported from directories in `src/node_modules` will ne

#### Preload

As before, pages and layout components can export a function that allows data to be loaded before rendering takes place.
As before, pages and layouts can export a function that allows data to be loaded before rendering takes place.

This function has been renamed from `preload` to [`load`](/docs/loading), and its API has changed. Instead of two arguments — `page` and `session` — there is a single argument that includes both, along with `fetch` (which replaces `this.fetch`) and a new `stuff` object.

Expand Down

0 comments on commit cff94c1

Please sign in to comment.