Skip to content

Commit 5cf1235

Browse files
committed
docs: params prop
1 parent a45ccdf commit 5cf1235

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,36 @@ 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. They also receive `params`, which is typed based on the route parameters.
42+
Pages can receive data from `load` functions via the `data` prop.
4343

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

55+
As of 2.24, pages also receive a `params` prop which is typed based on the route parameters. This is particularly useful alongside [remote functions](remote-functions):
56+
57+
```svelte
58+
<!--- file: src/routes/blog/[slug]/+page.svelte --->
59+
<script>
60+
import { getPost } from '$lib/server/db';
61+
62+
/** @type {import('./$types').PageProps} */
63+
let { params } = $props();
64+
65+
const post = $derived(await getPost(params.slug));
66+
</script>
67+
68+
<h1>{post.title}</h1>
69+
<div>{@html post.content}</div>
70+
```
71+
5772
> [!LEGACY]
5873
> `PageProps` was added in 2.16.0. In earlier versions, you had to type the `data` property manually with `PageData` instead, see [$types](#\$types).
5974
>

0 commit comments

Comments
 (0)