From 9c5494edd1dc8ac39b5992e95607bc5177b90329 Mon Sep 17 00:00:00 2001 From: "svelte-docs-bot[bot]" <196124396+svelte-docs-bot[bot]@users.noreply.github.com> Date: Thu, 24 Jul 2025 15:43:39 +0000 Subject: [PATCH] sync kit docs --- .../docs/kit/98-reference/10-@sveltejs-kit.md | 73 ++++++------- .../docs/kit/98-reference/20-$app-paths.md | 101 +++++++++++++++--- .../docs/kit/98-reference/20-$app-server.md | 4 +- .../docs/kit/98-reference/20-$app-types.md | 92 ++++++++++++++++ 4 files changed, 210 insertions(+), 60 deletions(-) create mode 100644 apps/svelte.dev/content/docs/kit/98-reference/20-$app-types.md diff --git a/apps/svelte.dev/content/docs/kit/98-reference/10-@sveltejs-kit.md b/apps/svelte.dev/content/docs/kit/98-reference/10-@sveltejs-kit.md index 943cc0e406..2f31f06f44 100644 --- a/apps/svelte.dev/content/docs/kit/98-reference/10-@sveltejs-kit.md +++ b/apps/svelte.dev/content/docs/kit/98-reference/10-@sveltejs-kit.md @@ -286,14 +286,13 @@ See [form actions](/docs/kit/form-actions) for more information. ```dts type Action< - Params extends Partial> = Partial< - Record - >, + Params extends + AppLayoutParams<'/'> = AppLayoutParams<'/'>, OutputData extends Record | void = Record< string, any > | void, - RouteId extends string | null = string | null + RouteId extends AppRouteId | null = AppRouteId | null > = ( event: RequestEvent ) => MaybePromise; @@ -377,14 +376,13 @@ See [form actions](/docs/kit/form-actions) for more information. ```dts type Actions< - Params extends Partial> = Partial< - Record - >, + Params extends + AppLayoutParams<'/'> = AppLayoutParams<'/'>, OutputData extends Record | void = Record< string, any > | void, - RouteId extends string | null = string | null + RouteId extends AppRouteId | null = AppRouteId | null > = Record>; ``` @@ -1208,9 +1206,8 @@ rather than using `Load` directly. ```dts type Load< - Params extends Partial> = Partial< - Record - >, + Params extends + AppLayoutParams<'/'> = AppLayoutParams<'/'>, InputData extends Record | null = Record< string, any @@ -1223,7 +1220,7 @@ type Load< string, unknown > | void = Record | void, - RouteId extends string | null = string | null + RouteId extends AppRouteId | null = AppRouteId | null > = ( event: LoadEvent ) => MaybePromise; @@ -1240,9 +1237,8 @@ rather than using `LoadEvent` directly. ```dts interface LoadEvent< - Params extends Partial> = Partial< - Record - >, + Params extends + AppLayoutParams<'/'> = AppLayoutParams<'/'>, Data extends Record | null = Record< string, any @@ -1251,7 +1247,7 @@ interface LoadEvent< string, any >, - RouteId extends string | null = string | null + RouteId extends AppRouteId | null = AppRouteId | null > extends NavigationEvent {/*…*/} ``` @@ -1526,10 +1522,9 @@ fails or is aborted. In the case of a `willUnload` navigation, the promise will ```dts interface NavigationEvent< - Params extends Partial> = Partial< - Record - >, - RouteId extends string | null = string | null + Params extends + AppLayoutParams<'/'> = AppLayoutParams<'/'>, + RouteId extends AppRouteId | null = AppRouteId | null > {/*…*/} ``` @@ -1732,18 +1727,16 @@ The shape of the [`page`](/docs/kit/$app-state#page) reactive object and the [`$ ```dts interface Page< - Params extends Record = Record< - string, - string - >, - RouteId extends string | null = string | null + Params extends + AppLayoutParams<'/'> = AppLayoutParams<'/'>, + RouteId extends AppRouteId | null = AppRouteId | null > {/*…*/} ```
```dts -url: URL; +url: URL & { pathname: ResolvedPathname }; ```
@@ -1921,10 +1914,9 @@ The location to redirect to. ```dts interface RequestEvent< - Params extends Partial> = Partial< - Record - >, - RouteId extends string | null = string | null + Params extends + AppLayoutParams<'/'> = AppLayoutParams<'/'>, + RouteId extends AppRouteId | null = AppRouteId | null > {/*…*/} ``` @@ -2136,10 +2128,9 @@ It receives `Params` as the first generic argument, which you can skip by using ```dts type RequestHandler< - Params extends Partial> = Partial< - Record - >, - RouteId extends string | null = string | null + Params extends + AppLayoutParams<'/'> = AppLayoutParams<'/'>, + RouteId extends AppRouteId | null = AppRouteId | null > = ( event: RequestEvent ) => MaybePromise; @@ -2497,9 +2488,8 @@ rather than using `ServerLoad` directly. ```dts type ServerLoad< - Params extends Partial> = Partial< - Record - >, + Params extends + AppLayoutParams<'/'> = AppLayoutParams<'/'>, ParentData extends Record = Record< string, any @@ -2508,7 +2498,7 @@ type ServerLoad< string, any > | void, - RouteId extends string | null = string | null + RouteId extends AppRouteId | null = AppRouteId | null > = ( event: ServerLoadEvent ) => MaybePromise; @@ -2522,14 +2512,13 @@ type ServerLoad< ```dts interface ServerLoadEvent< - Params extends Partial> = Partial< - Record - >, + Params extends + AppLayoutParams<'/'> = AppLayoutParams<'/'>, ParentData extends Record = Record< string, any >, - RouteId extends string | null = string | null + RouteId extends AppRouteId | null = AppRouteId | null > extends RequestEvent {/*…*/} ``` diff --git a/apps/svelte.dev/content/docs/kit/98-reference/20-$app-paths.md b/apps/svelte.dev/content/docs/kit/98-reference/20-$app-paths.md index b6740cb8ea..e754960562 100644 --- a/apps/svelte.dev/content/docs/kit/98-reference/20-$app-paths.md +++ b/apps/svelte.dev/content/docs/kit/98-reference/20-$app-paths.md @@ -7,11 +7,47 @@ title: $app/paths ```js // @noErrors -import { assets, base, resolveRoute } from '$app/paths'; +import { asset, assets, base, resolve, resolveRoute } from '$app/paths'; ``` +## asset + +
+ +Available since 2.26 + +
+ +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. + +During server rendering, the base path is relative and depends on the page currently being rendered. + +```svelte + + +a potato +``` + +
+ +```dts +function asset(file: Asset): string; +``` + +
+ + + ## assets +
+ +Use [`asset(...)`](/docs/kit/$app-paths#asset) instead + +
+ An absolute path that matches [`config.kit.paths.assets`](/docs/kit/configuration#paths). > [!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: ## base +
+ +Use [`resolve(...)`](/docs/kit/$app-paths#resolve) instead + +
+ A string that matches [`config.kit.paths.base`](/docs/kit/configuration#paths). Example usage: `Link` @@ -46,30 +88,57 @@ let base: '' | `/${string}`; -## resolveRoute +## resolve + +
+ +Available since 2.26 + +
+ +Resolve a pathname by prefixing it with the base path, if any, or resolve a route ID by populating dynamic segments with parameters. -Populate a route ID with params to resolve a pathname. +During server rendering, the base path is relative and depends on the page currently being rendered. ```js // @errors: 7031 -import { resolveRoute } from '$app/paths'; - -resolveRoute( - `/blog/[slug]/[...somethingElse]`, - { - slug: 'hello-world', - somethingElse: 'something/else' - } -); // `/blog/hello-world/something/else` +import { resolve } from '$app/paths'; + +// using a pathname +const resolved = resolve(`/blog/hello-world`); + +// using a route ID plus parameters +const resolved = resolve('/blog/[slug]', { + slug: 'hello-world' +}); +``` + +
+ +```dts +function resolve( + ...args: ResolveArgs +): ResolvedPathname; ``` +
+ + + +## resolveRoute + +
+ +Use [`resolve(...)`](/docs/kit/$app-paths#resolve) instead + +
+
```dts -function resolveRoute( - id: string, - params: Record -): string; +function resolveRoute( + ...args: ResolveArgs +): ResolvedPathname; ```
diff --git a/apps/svelte.dev/content/docs/kit/98-reference/20-$app-server.md b/apps/svelte.dev/content/docs/kit/98-reference/20-$app-server.md index 13c45a05d4..6307f34fe5 100644 --- a/apps/svelte.dev/content/docs/kit/98-reference/20-$app-server.md +++ b/apps/svelte.dev/content/docs/kit/98-reference/20-$app-server.md @@ -26,8 +26,8 @@ In environments without [`AsyncLocalStorage`](https://nodejs.org/api/async_conte ```dts function getRequestEvent(): RequestEvent< - Partial>, - string | null + AppLayoutParams<'/'>, + any >; ``` diff --git a/apps/svelte.dev/content/docs/kit/98-reference/20-$app-types.md b/apps/svelte.dev/content/docs/kit/98-reference/20-$app-types.md new file mode 100644 index 0000000000..465e50d791 --- /dev/null +++ b/apps/svelte.dev/content/docs/kit/98-reference/20-$app-types.md @@ -0,0 +1,92 @@ +--- +NOTE: do not edit this file, it is generated in apps/svelte.dev/scripts/sync-docs/index.ts +title: $app/types +--- + +This module contains generated types for the routes in your app. + +
+

Available since 2.26

+
+ +```js +// @noErrors +import type { RouteId, RouteParams, LayoutParams } from '$app/types'; +``` + +## Asset + +A union of all the filenames of assets contained in your `static` directory. + +
+ +```dts +type Asset = '/favicon.png' | '/robots.txt'; +``` + +
+ +## RouteId + +A union of all the route IDs in your app. Used for `page.route.id` and `event.route.id`. + +
+ +```dts +type RouteId = '/' | '/my-route' | '/my-other-route/[param]'; +``` + +
+ +## Pathname + +A union of all valid pathnames in your app. + +
+ +```dts +type Pathname = '/' | '/my-route' | `/my-other-route/${string}` & {}; +``` + +
+ +## ResolvedPathname + +`Pathname`, but possibly prefixed with a [base path](https://svelte.dev/docs/kit/configuration#paths). Used for `page.url.pathname`. + +
+ +```dts +type Pathname = `${'' | `/${string}`}/` | `${'' | `/${string}`}/my-route` | `${'' | `/${string}`}/my-other-route/${string}` | {}; +``` + +
+ +## RouteParams + +A utility for getting the parameters associated with a given route. + +```ts +// @errors: 2552 +type BlogParams = RouteParams<'/blog/[slug]'>; // { slug: string } +``` + +
+ +```dts +type RouteParams = { /* generated */ } | Record; +``` + +
+ +## LayoutParams + +A utility for getting the parameters associated with a given layout, which is similar to `RouteParams` but also includes optional parameters for any child route. + +
+ +```dts +type RouteParams = { /* generated */ } | Record; +``` + +