Skip to content

useSvelteKitResolve (JavaScript)

biome.json
{
"linter": {
"rules": {
"nursery": {
"useSvelteKitResolve": "error"
}
}
}
}

Require internal navigation in SvelteKit apps to use paths built with resolve().

SvelteKit’s resolve() from $app/paths prefixes a route with the app’s base path and checks it against the app’s routes. Passing a hand-written path to goto(), pushState(), or replaceState() breaks navigation when the app is served from a sub-path, and lets typos in routes go unnoticed.

pushState() and replaceState() also accept an empty string, which keeps the current URL for shallow routing.

Paths are also accepted when they come from a variable whose initializer uses resolve(), or from a variable or parameter annotated with the ResolvedPathname type from $app/types.

For navigation to external URLs, use window.location instead of goto().

import { goto } from "$app/navigation";
goto("/foo");
code-block.js:3:6 lint/nursery/useSvelteKitResolve ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ The path passed to goto() isn't built with resolve().

1 │ import { goto } from "$app/navigation";
2 │
> 3 │ goto("/foo");
│ ^^^^^^
4 │

ℹ Paths that aren't built with resolve() lack the app's base path, and SvelteKit can't check them against the app's routes.

ℹ Wrap the path in resolve() from $app/paths. To navigate to an external URL, use window.location instead.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

import { goto } from "$app/navigation";
import { resolve } from "$app/paths";
goto(resolve("/foo") + "/bar");
code-block.js:4:6 lint/nursery/useSvelteKitResolve ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ The path passed to goto() isn't built with resolve().

2 │ import { resolve } from "$app/paths";
3 │
> 4 │ goto(resolve("/foo") + "/bar");
│ ^^^^^^^^^^^^^^^^^^^^^^^^
5 │

ℹ Paths that aren't built with resolve() lack the app's base path, and SvelteKit can't check them against the app's routes.

ℹ Wrap the path in resolve() from $app/paths. To navigate to an external URL, use window.location instead.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

import { pushState } from "$app/navigation";
pushState("/foo", {});
code-block.js:3:11 lint/nursery/useSvelteKitResolve ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ The path passed to pushState() isn't built with resolve().

1 │ import { pushState } from "$app/navigation";
2 │
> 3 │ pushState("/foo", {});
│ ^^^^^^
4 │

ℹ Paths that aren't built with resolve() lack the app's base path, and SvelteKit can't check them against the app's routes.

ℹ Wrap the path in resolve() from $app/paths, or pass an empty string to keep the current URL.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

import { goto, pushState, replaceState } from "$app/navigation";
import { resolve } from "$app/paths";
goto(resolve("/foo"));
pushState(resolve("/foo"), {});
replaceState(resolve("/foo"), {});
// Shallow routing
pushState("", {});
replaceState("", {});
import { goto } from "$app/navigation";
import type { ResolvedPathname } from "$app/types";
function navigate(path: ResolvedPathname) {
goto(path);
}

Whether to ignore all goto() calls. Default: false.

biome.json
{
"linter": {
"rules": {
"nursery": {
"useSvelteKitResolve": {
"level": "on",
"options": {
"ignoreGoto": true
}
}
}
}
}
}
import { goto } from "$app/navigation";
goto("/foo");

Whether to ignore all pushState() calls. Default: false.

biome.json
{
"linter": {
"rules": {
"nursery": {
"useSvelteKitResolve": {
"level": "on",
"options": {
"ignorePushState": true
}
}
}
}
}
}
import { pushState } from "$app/navigation";
pushState("/foo", {});

Whether to ignore all replaceState() calls. Default: false.

biome.json
{
"linter": {
"rules": {
"nursery": {
"useSvelteKitResolve": {
"level": "on",
"options": {
"ignoreReplaceState": true
}
}
}
}
}
}
import { replaceState } from "$app/navigation";
replaceState("/foo", {});