Skip to content

Commit ad223f3

Browse files
dummdidummRich-HarrisConduitry
authored
App state tutorial (#1016)
* migrate everything but the page stores section to $app/state * move redirects from tutorial into handle hooks: keeps all redirects on one place, less prerendered pages for stuff that's increasingly rotten, fixes a bug with the specific redirects not working currently (they were missing from entries) * replace $app/stores tutorial with $app/state * bump kit * small tweaks * update * Update apps/svelte.dev/content/tutorial/03-sveltekit/08-app-state/01-page-state/index.md Co-authored-by: Conduitry <[email protected]> * Update apps/svelte.dev/content/tutorial/03-sveltekit/08-app-state/01-page-state/index.md * Update apps/svelte.dev/content/tutorial/03-sveltekit/08-app-state/02-navigating-state/index.md Co-authored-by: Conduitry <[email protected]> * Update apps/svelte.dev/content/tutorial/03-sveltekit/08-app-state/03-updated-state/index.md Co-authored-by: Conduitry <[email protected]> * Update apps/svelte.dev/content/tutorial/03-sveltekit/08-app-state/03-updated-state/index.md * Apply suggestions from code review * bump, use <page.data.component> directly * update * revert * only update kit * get the damn thing working * sure, prettier, let's suddenly start complaining about these files for some reason * undo some other upgrade that fucked up syntax highlighting for some insane reason. fuck me i fucking hate computers * i don't fucking believe this --------- Co-authored-by: Rich Harris <[email protected]> Co-authored-by: Conduitry <[email protected]>
1 parent 989d67f commit ad223f3

File tree

58 files changed

+759
-564
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+759
-564
lines changed

apps/svelte.dev/content/tutorial/+assets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"devDependencies": {
1010
"@rollup/wasm-node": "^4.25.0",
11-
"@sveltejs/kit": "^2.5",
11+
"@sveltejs/kit": "^2.12.1",
1212
"esbuild-wasm": "^0.21.5",
1313
"svelte": "^5.0.0",
1414
"vite": "^5.4"

apps/svelte.dev/content/tutorial/01-svelte/+assets/src/routes/+error.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script>
2-
import { page } from '$app/stores';
2+
import { page } from '$app/state';
33
</script>
44

5-
{#if $page.status === 404}
5+
{#if page.status === 404}
66
<h1>Not found</h1>
77
<p><a href="/">Go to /</a></p>
88
{:else}
@@ -11,8 +11,8 @@
1111
code
1212
<a
1313
target="_blank"
14-
href="https://http.dog/{$page.status}"
15-
>{$page.status}</a
14+
href="https://http.dog/{page.status}"
15+
>{page.status}</a
1616
>
1717
</p>
1818
{/if}

apps/svelte.dev/content/tutorial/02-advanced-svelte/+assets/src/routes/+error.svelte

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script>
2-
import { page } from '$app/stores';
2+
import { page } from '$app/state';
33
</script>
44

5-
{#if $page.status === 404}
5+
{#if page.status === 404}
66
<h1>Not found</h1>
77
<p><a href="/">Go to /</a></p>
88
{:else}
@@ -11,12 +11,12 @@
1111
code
1212
<a
1313
target="_blank"
14-
href="https://http.dog/{$page.status}"
15-
>{$page.status}</a
14+
href="https://http.dog/{page.status}"
15+
>{page.status}</a
1616
>
1717
</p>
1818

19-
<pre>{$page.error?.stack || ''}</pre>
19+
<pre>{page.error?.stack || ''}</pre>
2020
{/if}
2121

2222
<style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script>
2+
import { page } from '$app/state';
3+
let { children } = $props();
4+
</script>
5+
6+
<nav>
7+
<a href="/" aria-current={page.url.pathname === '/'}>
8+
home
9+
</a>
10+
11+
<a href="/about" aria-current={page.url.pathname === '/about'}>
12+
about
13+
</a>
14+
</nav>
15+
16+
{@render children()}

apps/svelte.dev/content/tutorial/03-sveltekit/08-stores/01-page-store/index.md renamed to apps/svelte.dev/content/tutorial/03-sveltekit/08-app-state/01-page-state/index.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
title: page
33
---
44

5-
> TODO link to stores exercise
6-
7-
As we learned earlier, Svelte stores are a place to put data that doesn't belong to an individual component.
8-
9-
SvelteKit makes three readonly stores available via the `$app/stores` module — `page`, `navigating` and `updated`. The one you'll use most often is [`page`](/docs/kit/@sveltejs-kit#Page), which provides information about the current page:
5+
SvelteKit makes three readonly state objects available via the `$app/state` module — `page`, `navigating` and `updated`. The one you'll use most often is [`page`](/docs/kit/@sveltejs-kit#Page), which provides information about the current page:
106

117
- `url` — the [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) of the current page
128
- `params` — the current page's [parameters](params)
@@ -16,25 +12,27 @@ SvelteKit makes three readonly stores available via the `$app/stores` module —
1612
- `data` — the data for the current page, combining the return values of all `load` functions
1713
- `form` — the data returned from a [form action](the-form-element)
1814

19-
As with any other store, you can reference its value in a component by prefixing its name with the `$` symbol. For example, we can access the current pathname as `$page.url.pathname`:
15+
Each of these properties is reactive, using `$state.raw` under the hood. Here's an example using `page.url.pathname`:
2016

2117
```svelte
2218
/// file: src/routes/+layout.svelte
2319
<script>
24-
+++import { page } from '$app/stores';+++
20+
+++import { page } from '$app/state';+++
2521
2622
let { children } = $props();
2723
</script>
2824
2925
<nav>
30-
<a href="/" +++aria-current={$page.url.pathname === '/'}+++>
26+
<a href="/" +++aria-current={page.url.pathname === '/'}+++>
3127
home
3228
</a>
3329
34-
<a href="/about" +++aria-current={$page.url.pathname === '/about'}+++>
30+
<a href="/about" +++aria-current={page.url.pathname === '/about'}+++>
3531
about
3632
</a>
3733
</nav>
3834
3935
{@render children()}
4036
```
37+
38+
> [!NOTE] Prior to SvelteKit 2.12, you had to use `$app/stores` for this, which provides a `$page` store with the same information. If you're currently using `$app/stores`, we advise you to migrate towards `$app/state` (requires Svelte 5).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script>
2+
import { page } from '$app/state';
3+
let { children } = $props();
4+
</script>
5+
6+
<nav>
7+
<a href="/" aria-current={page.url.pathname === '/'}>
8+
home
9+
</a>
10+
11+
<a href="/about" aria-current={page.url.pathname === '/about'}>
12+
about
13+
</a>
14+
</nav>
15+
16+
{@render children()}

0 commit comments

Comments
 (0)