Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 31 additions & 42 deletions apps/svelte.dev/content/docs/kit/98-reference/10-@sveltejs-kit.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,13 @@ See [form actions](/docs/kit/form-actions) for more information.

```dts
type Action<
Params extends Partial<Record<string, string>> = Partial<
Record<string, string>
>,
Params extends
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
OutputData extends Record<string, any> | void = Record<
string,
any
> | void,
RouteId extends string | null = string | null
RouteId extends AppRouteId | null = AppRouteId | null
> = (
event: RequestEvent<Params, RouteId>
) => MaybePromise<OutputData>;
Expand Down Expand Up @@ -377,14 +376,13 @@ See [form actions](/docs/kit/form-actions) for more information.

```dts
type Actions<
Params extends Partial<Record<string, string>> = Partial<
Record<string, string>
>,
Params extends
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
OutputData extends Record<string, any> | void = Record<
string,
any
> | void,
RouteId extends string | null = string | null
RouteId extends AppRouteId | null = AppRouteId | null
> = Record<string, Action<Params, OutputData, RouteId>>;
```

Expand Down Expand Up @@ -1208,9 +1206,8 @@ rather than using `Load` directly.

```dts
type Load<
Params extends Partial<Record<string, string>> = Partial<
Record<string, string>
>,
Params extends
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
InputData extends Record<string, unknown> | null = Record<
string,
any
Expand All @@ -1223,7 +1220,7 @@ type Load<
string,
unknown
> | void = Record<string, any> | void,
RouteId extends string | null = string | null
RouteId extends AppRouteId | null = AppRouteId | null
> = (
event: LoadEvent<Params, InputData, ParentData, RouteId>
) => MaybePromise<OutputData>;
Expand All @@ -1240,9 +1237,8 @@ rather than using `LoadEvent` directly.

```dts
interface LoadEvent<
Params extends Partial<Record<string, string>> = Partial<
Record<string, string>
>,
Params extends
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
Data extends Record<string, unknown> | null = Record<
string,
any
Expand All @@ -1251,7 +1247,7 @@ interface LoadEvent<
string,
any
>,
RouteId extends string | null = string | null
RouteId extends AppRouteId | null = AppRouteId | null
> extends NavigationEvent<Params, RouteId> {/*…*/}
```

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

```dts
interface NavigationEvent<
Params extends Partial<Record<string, string>> = Partial<
Record<string, string>
>,
RouteId extends string | null = string | null
Params extends
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
RouteId extends AppRouteId | null = AppRouteId | null
> {/*…*/}
```

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

```dts
interface Page<
Params extends Record<string, string> = Record<
string,
string
>,
RouteId extends string | null = string | null
Params extends
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
RouteId extends AppRouteId | null = AppRouteId | null
> {/*…*/}
```

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

```dts
url: URL;
url: URL & { pathname: ResolvedPathname };
```

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

```dts
interface RequestEvent<
Params extends Partial<Record<string, string>> = Partial<
Record<string, string>
>,
RouteId extends string | null = string | null
Params extends
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
RouteId extends AppRouteId | null = AppRouteId | null
> {/*…*/}
```

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

```dts
type RequestHandler<
Params extends Partial<Record<string, string>> = Partial<
Record<string, string>
>,
RouteId extends string | null = string | null
Params extends
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
RouteId extends AppRouteId | null = AppRouteId | null
> = (
event: RequestEvent<Params, RouteId>
) => MaybePromise<Response>;
Expand Down Expand Up @@ -2497,9 +2488,8 @@ rather than using `ServerLoad` directly.

```dts
type ServerLoad<
Params extends Partial<Record<string, string>> = Partial<
Record<string, string>
>,
Params extends
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
ParentData extends Record<string, any> = Record<
string,
any
Expand All @@ -2508,7 +2498,7 @@ type ServerLoad<
string,
any
> | void,
RouteId extends string | null = string | null
RouteId extends AppRouteId | null = AppRouteId | null
> = (
event: ServerLoadEvent<Params, ParentData, RouteId>
) => MaybePromise<OutputData>;
Expand All @@ -2522,14 +2512,13 @@ type ServerLoad<

```dts
interface ServerLoadEvent<
Params extends Partial<Record<string, string>> = Partial<
Record<string, string>
>,
Params extends
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
ParentData extends Record<string, any> = Record<
string,
any
>,
RouteId extends string | null = string | null
RouteId extends AppRouteId | null = AppRouteId | null
> extends RequestEvent<Params, RouteId> {/*…*/}
```

Expand Down
101 changes: 85 additions & 16 deletions apps/svelte.dev/content/docs/kit/98-reference/20-$app-paths.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<blockquote class="since note">

Available since 2.26

</blockquote>

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
<script>
import { asset } from '$app/paths';
</script>

<img alt="a potato" src={asset('potato.jpg')} />
```

<div class="ts-block">

```dts
function asset(file: Asset): string;
```

</div>



## assets

<blockquote class="tag deprecated note">

Use [`asset(...)`](/docs/kit/$app-paths#asset) instead

</blockquote>

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.
Expand All @@ -32,6 +68,12 @@ let assets:

## base

<blockquote class="tag deprecated note">

Use [`resolve(...)`](/docs/kit/$app-paths#resolve) instead

</blockquote>

A string that matches [`config.kit.paths.base`](/docs/kit/configuration#paths).

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



## resolveRoute
## resolve

<blockquote class="since note">

Available since 2.26

</blockquote>

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'
});
```

<div class="ts-block">

```dts
function resolve<T extends RouteId | Pathname>(
...args: ResolveArgs<T>
): ResolvedPathname;
```

</div>



## resolveRoute

<blockquote class="tag deprecated note">

Use [`resolve(...)`](/docs/kit/$app-paths#resolve) instead

</blockquote>

<div class="ts-block">

```dts
function resolveRoute(
id: string,
params: Record<string, string | undefined>
): string;
function resolveRoute<T extends RouteId | Pathname>(
...args: ResolveArgs<T>
): ResolvedPathname;
```

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ In environments without [`AsyncLocalStorage`](https://nodejs.org/api/async_conte

```dts
function getRequestEvent(): RequestEvent<
Partial<Record<string, string>>,
string | null
AppLayoutParams<'/'>,
any
>;
```

Expand Down
Loading