-
-
Notifications
You must be signed in to change notification settings - Fork 187
App state tutorial #1016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
App state tutorial #1016
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e7d89c0
migrate everything but the page stores section to $app/state
dummdidumm 4f44c34
move redirects from tutorial into handle hooks: keeps all redirects o…
dummdidumm 5ca62e0
replace $app/stores tutorial with $app/state
dummdidumm 3b43f5b
bump kit
Rich-Harris d3716d1
small tweaks
Rich-Harris a3707f4
merge
Rich-Harris 1d3731f
update
Rich-Harris e280846
Update apps/svelte.dev/content/tutorial/03-sveltekit/08-app-state/01-…
Rich-Harris 6571278
Update apps/svelte.dev/content/tutorial/03-sveltekit/08-app-state/01-…
Rich-Harris 850dde0
Update apps/svelte.dev/content/tutorial/03-sveltekit/08-app-state/02-…
Rich-Harris 0ae2d10
Update apps/svelte.dev/content/tutorial/03-sveltekit/08-app-state/03-…
Rich-Harris 562b811
Update apps/svelte.dev/content/tutorial/03-sveltekit/08-app-state/03-…
Rich-Harris 224733d
Apply suggestions from code review
Rich-Harris ba928ff
bump, use <page.data.component> directly
Rich-Harris d6a4c66
update
Rich-Harris d7a4122
revert
Rich-Harris 68d9cf3
only update kit
Rich-Harris 0edd05d
get the damn thing working
Rich-Harris 7670901
sure, prettier, let's suddenly start complaining about these files fo…
Rich-Harris 8ea40e5
undo some other upgrade that fucked up syntax highlighting for some i…
Rich-Harris eb0f10b
i don't fucking believe this
Rich-Harris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions
16
.../tutorial/03-sveltekit/08-app-state/01-page-state/+assets/app-b/src/routes/+layout.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<script> | ||
import { page } from '$app/state'; | ||
let { children } = $props(); | ||
</script> | ||
|
||
<nav> | ||
<a href="/" aria-current={page.url.pathname === '/'}> | ||
home | ||
</a> | ||
|
||
<a href="/about" aria-current={page.url.pathname === '/about'}> | ||
about | ||
</a> | ||
</nav> | ||
|
||
{@render children()} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...ial/03-sveltekit/08-app-state/02-navigating-state/+assets/app-a/src/routes/+layout.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<script> | ||
import { page } from '$app/state'; | ||
let { children } = $props(); | ||
</script> | ||
|
||
<nav> | ||
<a href="/" aria-current={page.url.pathname === '/'}> | ||
home | ||
</a> | ||
|
||
<a href="/about" aria-current={page.url.pathname === '/about'}> | ||
about | ||
</a> | ||
</nav> | ||
|
||
{@render children()} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
...ial/03-sveltekit/08-app-state/02-navigating-state/+assets/app-b/src/routes/+layout.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<script> | ||
import { page, navigating } from '$app/state'; | ||
let { children } = $props(); | ||
</script> | ||
|
||
<nav> | ||
<a href="/" aria-current={page.url.pathname === '/'}> | ||
home | ||
</a> | ||
|
||
<a href="/about" aria-current={page.url.pathname === '/about'}> | ||
about | ||
</a> | ||
|
||
{#if navigating.to} | ||
navigating to {navigating.to.url.pathname} | ||
{/if} | ||
</nav> | ||
|
||
{@render children()} |
39 changes: 39 additions & 0 deletions
39
...lte.dev/content/tutorial/03-sveltekit/08-app-state/02-navigating-state/index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
title: navigating | ||
--- | ||
|
||
The `navigating` object represents the current navigation. When a navigation starts — because of a link click, or a back/forward navigation, or a programmatic `goto` — the value of `navigating` will become an object with the following properties: | ||
|
||
- `from` and `to` — objects with `params`, `route` and `url` properties | ||
- `type` — the type of navigation, e.g. `link`, `popstate` or `goto` | ||
|
||
> [!NOTE] For complete type information visit the [`Navigation`](/docs/kit/@sveltejs-kit#Navigation) documentation. | ||
|
||
It can be used to show a loading indicator for long-running navigations. In this exercise, `src/routes/+page.server.js` and `src/routes/about/+page.server.js` both have an artificial delay. Inside `src/routes/+layout.svelte`, import the `navigating` object and add a message to the nav bar: | ||
|
||
```svelte | ||
/// file: src/routes/+layout.svelte | ||
<script> | ||
import { page, +++navigating+++ } from '$app/state'; | ||
|
||
let { children } = $props(); | ||
</script> | ||
|
||
<nav> | ||
<a href="/" aria-current={page.url.pathname === '/'}> | ||
home | ||
</a> | ||
|
||
<a href="/about" aria-current={page.url.pathname === '/about'}> | ||
about | ||
</a> | ||
|
||
+++ {#if navigating.to} | ||
navigating to {navigating.to.url.pathname} | ||
{/if}+++ | ||
</nav> | ||
|
||
{@render children()} | ||
``` | ||
|
||
> [!NOTE] Prior to SvelteKit 2.12, you had to use `$app/stores` for this, which provides a `$navigating` store with the same information. If you're currently using `$app/stores`, we advise you to migrate towards `$app/state` (requires Svelte 5). |
10 changes: 5 additions & 5 deletions
10
...e/+assets/app-a/src/routes/+layout.svelte → ...e/+assets/app-a/src/routes/+layout.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
apps/svelte.dev/content/tutorial/03-sveltekit/08-app-state/index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: $app/state | ||
--- |
16 changes: 0 additions & 16 deletions
16
...ent/tutorial/03-sveltekit/08-stores/01-page-store/+assets/app-b/src/routes/+layout.svelte
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
...torial/03-sveltekit/08-stores/02-navigating-store/+assets/app-a/src/routes/+layout.svelte
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
...torial/03-sveltekit/08-stores/02-navigating-store/+assets/app-b/src/routes/+layout.svelte
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
...svelte.dev/content/tutorial/03-sveltekit/08-stores/02-navigating-store/index.md
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
apps/svelte.dev/content/tutorial/03-sveltekit/08-stores/index.md
This file was deleted.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
...3-sveltekit/09-errors-and-redirects/02-error-pages/+assets/app-b/src/routes/+error.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
<script> | ||
import { page } from '$app/stores'; | ||
import { page } from '$app/state'; | ||
import { emojis } from './emojis.js'; | ||
</script> | ||
|
||
<h1>{$page.status} {$page.error.message}</h1> | ||
<h1>{page.status} {page.error.message}</h1> | ||
<span style="font-size: 10em"> | ||
{emojis[$page.status] ?? emojis[500]} | ||
{emojis[page.status] ?? emojis[500]} | ||
</span> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.