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/05-load.md
+3-20
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ export function load(event) {
18
18
19
19
### Input properties
20
20
21
-
The argument to a `load` function is a `LoadEvent` (or, for server-only `load` functions, a `ServerLoadEvent` which inherits `clientAddress`, `locals`, `platform` and `request` from `RequestEvent`). All events have the following properties:
21
+
The argument to a `load` function is a `LoadEvent` (or, for server-only `load` functions, a `ServerLoadEvent` which inherits `clientAddress`, `cookies`, `locals`, `platform` and `request` from `RequestEvent`). All events have the following properties:
If you need to set headers for the response, you can do so using the `setHeaders` method. This is useful if you want the page to be cached, for example:
Setting the same header multiple times (even in separate `load` functions) is an error — you can only set a given header once.
242
243
243
-
The exception is `set-cookie`, which can be set multiple times and can be passed an array of strings:
244
-
245
-
```js
246
-
/// file: src/routes/+layout.server.js
247
-
/**@type{import('./$types').LayoutLoad}*/
248
-
exportasyncfunctionload({ setHeaders }) {
249
-
setHeaders({
250
-
'set-cookie':'a=1; HttpOnly'
251
-
});
252
-
253
-
setHeaders({
254
-
'set-cookie':'b=2; HttpOnly'
255
-
});
256
-
257
-
setHeaders({
258
-
'set-cookie': ['c=3; HttpOnly', 'd=4; HttpOnly']
259
-
});
260
-
}
261
-
```
244
+
You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](/docs/types#sveltejs-kit-cookies) API in a server-only `load` function instead.
0 commit comments