Skip to content

Commit 7ac7f79

Browse files
Sync kit docs (#1429)
sync kit docs Co-authored-by: svelte-docs-bot[bot] <196124396+svelte-docs-bot[bot]@users.noreply.github.com>
1 parent 8839d73 commit 7ac7f79

File tree

4 files changed

+210
-60
lines changed

4 files changed

+210
-60
lines changed

apps/svelte.dev/content/docs/kit/98-reference/[email protected]

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,13 @@ See [form actions](/docs/kit/form-actions) for more information.
286286

287287
```dts
288288
type Action<
289-
Params extends Partial<Record<string, string>> = Partial<
290-
Record<string, string>
291-
>,
289+
Params extends
290+
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
292291
OutputData extends Record<string, any> | void = Record<
293292
string,
294293
any
295294
> | void,
296-
RouteId extends string | null = string | null
295+
RouteId extends AppRouteId | null = AppRouteId | null
297296
> = (
298297
event: RequestEvent<Params, RouteId>
299298
) => MaybePromise<OutputData>;
@@ -377,14 +376,13 @@ See [form actions](/docs/kit/form-actions) for more information.
377376

378377
```dts
379378
type Actions<
380-
Params extends Partial<Record<string, string>> = Partial<
381-
Record<string, string>
382-
>,
379+
Params extends
380+
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
383381
OutputData extends Record<string, any> | void = Record<
384382
string,
385383
any
386384
> | void,
387-
RouteId extends string | null = string | null
385+
RouteId extends AppRouteId | null = AppRouteId | null
388386
> = Record<string, Action<Params, OutputData, RouteId>>;
389387
```
390388

@@ -1208,9 +1206,8 @@ rather than using `Load` directly.
12081206

12091207
```dts
12101208
type Load<
1211-
Params extends Partial<Record<string, string>> = Partial<
1212-
Record<string, string>
1213-
>,
1209+
Params extends
1210+
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
12141211
InputData extends Record<string, unknown> | null = Record<
12151212
string,
12161213
any
@@ -1223,7 +1220,7 @@ type Load<
12231220
string,
12241221
unknown
12251222
> | void = Record<string, any> | void,
1226-
RouteId extends string | null = string | null
1223+
RouteId extends AppRouteId | null = AppRouteId | null
12271224
> = (
12281225
event: LoadEvent<Params, InputData, ParentData, RouteId>
12291226
) => MaybePromise<OutputData>;
@@ -1240,9 +1237,8 @@ rather than using `LoadEvent` directly.
12401237

12411238
```dts
12421239
interface LoadEvent<
1243-
Params extends Partial<Record<string, string>> = Partial<
1244-
Record<string, string>
1245-
>,
1240+
Params extends
1241+
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
12461242
Data extends Record<string, unknown> | null = Record<
12471243
string,
12481244
any
@@ -1251,7 +1247,7 @@ interface LoadEvent<
12511247
string,
12521248
any
12531249
>,
1254-
RouteId extends string | null = string | null
1250+
RouteId extends AppRouteId | null = AppRouteId | null
12551251
> extends NavigationEvent<Params, RouteId> {/*…*/}
12561252
```
12571253

@@ -1526,10 +1522,9 @@ fails or is aborted. In the case of a `willUnload` navigation, the promise will
15261522

15271523
```dts
15281524
interface NavigationEvent<
1529-
Params extends Partial<Record<string, string>> = Partial<
1530-
Record<string, string>
1531-
>,
1532-
RouteId extends string | null = string | null
1525+
Params extends
1526+
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1527+
RouteId extends AppRouteId | null = AppRouteId | null
15331528
> {/*…*/}
15341529
```
15351530

@@ -1732,18 +1727,16 @@ The shape of the [`page`](/docs/kit/$app-state#page) reactive object and the [`$
17321727

17331728
```dts
17341729
interface Page<
1735-
Params extends Record<string, string> = Record<
1736-
string,
1737-
string
1738-
>,
1739-
RouteId extends string | null = string | null
1730+
Params extends
1731+
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1732+
RouteId extends AppRouteId | null = AppRouteId | null
17401733
> {/*…*/}
17411734
```
17421735

17431736
<div class="ts-block-property">
17441737

17451738
```dts
1746-
url: URL;
1739+
url: URL & { pathname: ResolvedPathname };
17471740
```
17481741

17491742
<div class="ts-block-property-details">
@@ -1921,10 +1914,9 @@ The location to redirect to.
19211914

19221915
```dts
19231916
interface RequestEvent<
1924-
Params extends Partial<Record<string, string>> = Partial<
1925-
Record<string, string>
1926-
>,
1927-
RouteId extends string | null = string | null
1917+
Params extends
1918+
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1919+
RouteId extends AppRouteId | null = AppRouteId | null
19281920
> {/*…*/}
19291921
```
19301922

@@ -2136,10 +2128,9 @@ It receives `Params` as the first generic argument, which you can skip by using
21362128

21372129
```dts
21382130
type RequestHandler<
2139-
Params extends Partial<Record<string, string>> = Partial<
2140-
Record<string, string>
2141-
>,
2142-
RouteId extends string | null = string | null
2131+
Params extends
2132+
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
2133+
RouteId extends AppRouteId | null = AppRouteId | null
21432134
> = (
21442135
event: RequestEvent<Params, RouteId>
21452136
) => MaybePromise<Response>;
@@ -2497,9 +2488,8 @@ rather than using `ServerLoad` directly.
24972488

24982489
```dts
24992490
type ServerLoad<
2500-
Params extends Partial<Record<string, string>> = Partial<
2501-
Record<string, string>
2502-
>,
2491+
Params extends
2492+
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
25032493
ParentData extends Record<string, any> = Record<
25042494
string,
25052495
any
@@ -2508,7 +2498,7 @@ type ServerLoad<
25082498
string,
25092499
any
25102500
> | void,
2511-
RouteId extends string | null = string | null
2501+
RouteId extends AppRouteId | null = AppRouteId | null
25122502
> = (
25132503
event: ServerLoadEvent<Params, ParentData, RouteId>
25142504
) => MaybePromise<OutputData>;
@@ -2522,14 +2512,13 @@ type ServerLoad<
25222512

25232513
```dts
25242514
interface ServerLoadEvent<
2525-
Params extends Partial<Record<string, string>> = Partial<
2526-
Record<string, string>
2527-
>,
2515+
Params extends
2516+
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
25282517
ParentData extends Record<string, any> = Record<
25292518
string,
25302519
any
25312520
>,
2532-
RouteId extends string | null = string | null
2521+
RouteId extends AppRouteId | null = AppRouteId | null
25332522
> extends RequestEvent<Params, RouteId> {/*…*/}
25342523
```
25352524

apps/svelte.dev/content/docs/kit/98-reference/20-$app-paths.md

Lines changed: 85 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,47 @@ title: $app/paths
77

88
```js
99
// @noErrors
10-
import { assets, base, resolveRoute } from '$app/paths';
10+
import { asset, assets, base, resolve, resolveRoute } from '$app/paths';
1111
```
1212

13+
## asset
14+
15+
<blockquote class="since note">
16+
17+
Available since 2.26
18+
19+
</blockquote>
20+
21+
Resolve the URL of an asset in your `static` directory, by prefixing it with [`config.kit.paths.assets`](/docs/kit/configuration#paths) if configured, or otherwise by prefixing it with the base path.
22+
23+
During server rendering, the base path is relative and depends on the page currently being rendered.
24+
25+
```svelte
26+
<script>
27+
import { asset } from '$app/paths';
28+
</script>
29+
30+
<img alt="a potato" src={asset('potato.jpg')} />
31+
```
32+
33+
<div class="ts-block">
34+
35+
```dts
36+
function asset(file: Asset): string;
37+
```
38+
39+
</div>
40+
41+
42+
1343
## assets
1444

45+
<blockquote class="tag deprecated note">
46+
47+
Use [`asset(...)`](/docs/kit/$app-paths#asset) instead
48+
49+
</blockquote>
50+
1551
An absolute path that matches [`config.kit.paths.assets`](/docs/kit/configuration#paths).
1652

1753
> [!NOTE] If a value for `config.kit.paths.assets` is specified, it will be replaced with `'/_svelte_kit_assets'` during `vite dev` or `vite preview`, since the assets don't yet live at their eventual URL.
@@ -32,6 +68,12 @@ let assets:
3268

3369
## base
3470

71+
<blockquote class="tag deprecated note">
72+
73+
Use [`resolve(...)`](/docs/kit/$app-paths#resolve) instead
74+
75+
</blockquote>
76+
3577
A string that matches [`config.kit.paths.base`](/docs/kit/configuration#paths).
3678

3779
Example usage: `<a href="{base}/your-page">Link</a>`
@@ -46,30 +88,57 @@ let base: '' | `/${string}`;
4688

4789

4890

49-
## resolveRoute
91+
## resolve
92+
93+
<blockquote class="since note">
94+
95+
Available since 2.26
96+
97+
</blockquote>
98+
99+
Resolve a pathname by prefixing it with the base path, if any, or resolve a route ID by populating dynamic segments with parameters.
50100

51-
Populate a route ID with params to resolve a pathname.
101+
During server rendering, the base path is relative and depends on the page currently being rendered.
52102

53103
```js
54104
// @errors: 7031
55-
import { resolveRoute } from '$app/paths';
56-
57-
resolveRoute(
58-
`/blog/[slug]/[...somethingElse]`,
59-
{
60-
slug: 'hello-world',
61-
somethingElse: 'something/else'
62-
}
63-
); // `/blog/hello-world/something/else`
105+
import { resolve } from '$app/paths';
106+
107+
// using a pathname
108+
const resolved = resolve(`/blog/hello-world`);
109+
110+
// using a route ID plus parameters
111+
const resolved = resolve('/blog/[slug]', {
112+
slug: 'hello-world'
113+
});
114+
```
115+
116+
<div class="ts-block">
117+
118+
```dts
119+
function resolve<T extends RouteId | Pathname>(
120+
...args: ResolveArgs<T>
121+
): ResolvedPathname;
64122
```
65123

124+
</div>
125+
126+
127+
128+
## resolveRoute
129+
130+
<blockquote class="tag deprecated note">
131+
132+
Use [`resolve(...)`](/docs/kit/$app-paths#resolve) instead
133+
134+
</blockquote>
135+
66136
<div class="ts-block">
67137

68138
```dts
69-
function resolveRoute(
70-
id: string,
71-
params: Record<string, string | undefined>
72-
): string;
139+
function resolveRoute<T extends RouteId | Pathname>(
140+
...args: ResolveArgs<T>
141+
): ResolvedPathname;
73142
```
74143

75144
</div>

apps/svelte.dev/content/docs/kit/98-reference/20-$app-server.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ In environments without [`AsyncLocalStorage`](https://nodejs.org/api/async_conte
2626

2727
```dts
2828
function getRequestEvent(): RequestEvent<
29-
Partial<Record<string, string>>,
30-
string | null
29+
AppLayoutParams<'/'>,
30+
any
3131
>;
3232
```
3333

0 commit comments

Comments
 (0)