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
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
+
<divclass="ts-block">
34
+
35
+
```dts
36
+
function asset(file: Asset): string;
37
+
```
38
+
39
+
</div>
40
+
41
+
42
+
13
43
## assets
14
44
45
+
<blockquoteclass="tag deprecated note">
46
+
47
+
Use [`asset(...)`](/docs/kit/$app-paths#asset) instead
48
+
49
+
</blockquote>
50
+
15
51
An absolute path that matches [`config.kit.paths.assets`](/docs/kit/configuration#paths).
16
52
17
53
> [!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:
32
68
33
69
## base
34
70
71
+
<blockquoteclass="tag deprecated note">
72
+
73
+
Use [`resolve(...)`](/docs/kit/$app-paths#resolve) instead
74
+
75
+
</blockquote>
76
+
35
77
A string that matches [`config.kit.paths.base`](/docs/kit/configuration#paths).
36
78
37
79
Example usage: `<a href="{base}/your-page">Link</a>`
@@ -46,30 +88,57 @@ let base: '' | `/${string}`;
46
88
47
89
48
90
49
-
## resolveRoute
91
+
## resolve
92
+
93
+
<blockquoteclass="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.
50
100
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.
52
102
53
103
```js
54
104
// @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
+
constresolved=resolve(`/blog/hello-world`);
109
+
110
+
// using a route ID plus parameters
111
+
constresolved=resolve('/blog/[slug]', {
112
+
slug:'hello-world'
113
+
});
114
+
```
115
+
116
+
<divclass="ts-block">
117
+
118
+
```dts
119
+
function resolve<T extends RouteId | Pathname>(
120
+
...args: ResolveArgs<T>
121
+
): ResolvedPathname;
64
122
```
65
123
124
+
</div>
125
+
126
+
127
+
128
+
## resolveRoute
129
+
130
+
<blockquoteclass="tag deprecated note">
131
+
132
+
Use [`resolve(...)`](/docs/kit/$app-paths#resolve) instead
133
+
134
+
</blockquote>
135
+
66
136
<divclass="ts-block">
67
137
68
138
```dts
69
-
function resolveRoute(
70
-
id: string,
71
-
params: Record<string, string | undefined>
72
-
): string;
139
+
function resolveRoute<T extends RouteId | Pathname>(
0 commit comments