You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/docs/20-core-concepts/10-routing.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,20 +19,20 @@ Each route directory contains one or more _route files_, which can be identified
19
19
A `+page.svelte` component defines a page of your app. By default, pages are rendered both on the server ([SSR](glossary#ssr)) for the initial request and in the browser ([CSR](glossary#csr)) for subsequent navigation.
@@ -119,7 +119,7 @@ A `+page.server.js` file can also export _actions_. If `load` lets you read data
119
119
If an error occurs during `load`, SvelteKit will render a default error page. You can customise this error page on a per-route basis by adding an `+error.svelte` file:
@@ -286,7 +286,7 @@ If an error is thrown (either `throw error(...)` or an unexpected error), the re
286
286
By exporting `POST`/`PUT`/`PATCH`/`DELETE`/`OPTIONS`/`HEAD` handlers, `+server.js` files can be used to create a complete API:
287
287
288
288
```svelte
289
-
/// file: src/routes/add/+page.svelte
289
+
<!--- file: src/routes/add/+page.svelte--->
290
290
<script>
291
291
let a =0;
292
292
let b =0;
@@ -340,7 +340,7 @@ Throughout the examples above, we've been importing types from a `$types.d.ts` f
340
340
For example, annotating `exportlet data` with `PageData` (or `LayoutData`, for a `+layout.svelte` file) tells TypeScript that the type of `data` is whatever was returned from `load`:
@@ -141,7 +141,7 @@ The `+page.svelte` component, and each `+layout.svelte` component above it, has
141
141
In some cases, we might need the opposite — a parent layout might need to access page data or data from a child layout. For example, the root layout might want to access a `title` property returned from a `load` function in `+page.js` or `+page.server.js`. This can be done with `$page.data`:
Form actions are the preferred way to send data to the server, since they can be progressively enhanced, but you can also use [`+server.js`](routing#server) files to expose (for example) a JSON API. Here's how such an interaction could look like:
457
457
458
458
```svelte
459
-
/// file: send-message/+page.svelte
459
+
<!--- file: send-message/+page.svelte --->
460
460
<script>
461
461
function rerun() {
462
462
fetch('/api/ci', {
@@ -469,7 +469,7 @@ Form actions are the preferred way to send data to the server, since they can be
Copy file name to clipboardExpand all lines: documentation/docs/20-core-concepts/50-state-management.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,7 +84,7 @@ If you're not using SSR, then there's no risk of accidentally exposing one user'
84
84
You might wonder how we're able to use `$page.data` and other [app stores](modules#$app-stores) if we can't use our own stores. The answer is that app stores on the server use Svelte's [context API](https://learn.svelte.dev/tutorial/context-api) — the store is attached to the component tree with `setContext`, and when you subscribe you retrieve it with `getContext`. We can do the same thing with our own stores:
85
85
86
86
```svelte
87
-
/// file: src/routes/+layout.svelte
87
+
<!--- file: src/routes/+layout.svelte --->
88
88
<script>
89
89
import { setContext } from 'svelte';
90
90
import { writable } from 'svelte/store';
@@ -102,7 +102,7 @@ You might wonder how we're able to use `$page.data` and other [app stores](modul
102
102
```
103
103
104
104
```svelte
105
-
/// file: src/routes/user/+page.svelte
105
+
<!--- file: src/routes/user/+page.svelte --->
106
106
<script>
107
107
import { getContext } from 'svelte';
108
108
@@ -122,7 +122,7 @@ If you're not using SSR (and can guarantee that you won't need to use SSR in fut
122
122
When you navigate around your application, SvelteKit reuses existing layout and page components. For example, if you have a route like this...
Copy file name to clipboardExpand all lines: documentation/docs/30-advanced/10-advanced-routing.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -254,7 +254,7 @@ src/routes/
254
254
Not all use cases are suited for layout grouping, nor should you feel compelled to use them. It might be that your use case would result in complex `(group)` nesting, or that you don't want to introduce a `(group)` for a single outlier. It's perfectly fine to use other means such as composition (reusable `load` functions or Svelte components) or if-statements to achieve what you want. The following example shows a layout that rewinds to the root layout and reuses components and functions that other layouts can also use:
This tells SvelteKit to set the response status code to 404 and render an [`+error.svelte`](routing#error) component, where `$page.error` is the object provided as the second argument to `error(...)`.
Copy file name to clipboardExpand all lines: documentation/docs/40-best-practices/10-accessibility.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ Since navigation between pages in SvelteKit happens without reloading the page (
17
17
Because of this behavior, every page in your app should have a unique, descriptive title. In SvelteKit, you can do this by placing a `<svelte:head>` element on each page:
> For this to work, your own `tsconfig.json` or `jsconfig.json` should extend from the generated `.svelte-kit/tsconfig.json` (where `.svelte-kit` is your [`outDir`](configuration#outdir)):
0 commit comments