Skip to content

Commit c48bd79

Browse files
docs: document typed params in page props
1 parent 3cbaac2 commit c48bd79

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

documentation/docs/20-core-concepts/10-routing.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,17 @@ A `+page.svelte` component defines a page of your app. By default, pages are ren
3939

4040
> [!NOTE] SvelteKit uses `<a>` elements to navigate between routes, rather than a framework-specific `<Link>` component.
4141
42-
Pages can receive data from `load` functions via the `data` prop.
42+
Pages can receive data from `load` functions via the `data` prop. They also receive `params`, which is typed based on the route parameters.
4343

4444
```svelte
4545
<!--- file: src/routes/blog/[slug]/+page.svelte --->
4646
<script>
4747
/** @type {import('./$types').PageProps} */
48-
let { data } = $props();
48+
let { data, params } = $props();
4949
</script>
5050
5151
<h1>{data.title}</h1>
52+
<p>slug: {params.slug}</p>
5253
<div>{@html data.content}</div>
5354
```
5455

@@ -393,13 +394,13 @@ export async function fallback({ request }) {
393394
394395
Throughout the examples above, we've been importing types from a `$types.d.ts` file. This is a file SvelteKit creates for you in a hidden directory if you're using TypeScript (or JavaScript with JSDoc type annotations) to give you type safety when working with your root files.
395396
396-
For example, annotating `let { data } = $props()` with `PageProps` (or `LayoutProps`, for a `+layout.svelte` file) tells TypeScript that the type of `data` is whatever was returned from `load`:
397+
For example, annotating `let { data, params } = $props()` with `PageProps` (or `LayoutProps`, for a `+layout.svelte` file) tells TypeScript that the type of `data` is whatever was returned from `load`, and that `params` matches the route parameters:
397398
398399
```svelte
399400
<!--- file: src/routes/blog/[slug]/+page.svelte --->
400401
<script>
401402
/** @type {import('./$types').PageProps} */
402-
let { data } = $props();
403+
let { data, params } = $props();
403404
</script>
404405
```
405406

0 commit comments

Comments
 (0)