跳至主要内容

$app/paths

import { let assets: "" | `https://${string}` | `http://${string}` | "/_svelte_kit_assets"

An absolute path that matches config.kit.paths.assets.

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.

assets
, let base: "" | `/${string}`

A string that matches config.kit.paths.base.

Example usage: <a href="{base}/your-page">Link</a>

base
, function resolveRoute(id: string, params: Record<string, string | undefined>): string

Populate a route ID with params to resolve a pathname.

@examplejs import { resolveRoute } from '$app/paths'; resolveRoute( `/blog/[slug]/[...somethingElse]`, { slug: 'hello-world', somethingElse: 'something/else' } ); // `/blog/hello-world/something/else`
resolveRoute
} from '$app/paths';

assets

config.kit.paths.assets匹配的绝对路径。

如果指定了config.kit.paths.assets的值,则在vite devvite preview期间它将被替换为'/_svelte_kit_assets',因为资产尚未位于其最终 URL。

let assets:
	| ''
	| `https://${string}`
	| `http://${string}`
	| '/_svelte_kit_assets';

base

config.kit.paths.base匹配的字符串。

示例用法:<a href="{base}/your-page">链接</a>

let base: '' | `/${string}`;

resolveRoute

使用参数填充路由 ID 以解析路径名。

import { function resolveRoute(id: string, params: Record<string, string | undefined>): string

Populate a route ID with params to resolve a pathname.

@examplejs import { resolveRoute } from '$app/paths'; resolveRoute( `/blog/[slug]/[...somethingElse]`, { slug: 'hello-world', somethingElse: 'something/else' } ); // `/blog/hello-world/something/else`
resolveRoute
} from '$app/paths';
function resolveRoute(id: string, params: Record<string, string | undefined>): string

Populate a route ID with params to resolve a pathname.

@examplejs import { resolveRoute } from '$app/paths'; resolveRoute( `/blog/[slug]/[...somethingElse]`, { slug: 'hello-world', somethingElse: 'something/else' } ); // `/blog/hello-world/something/else`
resolveRoute
(
`/blog/[slug]/[...somethingElse]`, { slug: stringslug: 'hello-world', somethingElse: stringsomethingElse: 'something/else' } ); // `/blog/hello-world/something/else`
function resolveRoute(
	id: string,
	params: Record<string, string | undefined>
): string;

在 GitHub 上编辑此页面

上一页 下一页