useSvelteKitResolve (JavaScript)
Summary
Section titled “Summary”- Rule available since:
v2.6.0 - Diagnostic Category:
lint/nursery/useSvelteKitResolve - This rule doesn’t have a fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
- Sources:
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useSvelteKitResolve": "error" } } }}Description
Section titled “Description”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().
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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 routingpushState("", {});replaceState("", {});import { goto } from "$app/navigation";import type { ResolvedPathname } from "$app/types";
function navigate(path: ResolvedPathname) { goto(path);}Options
Section titled “Options”ignoreGoto
Section titled “ignoreGoto”Whether to ignore all goto() calls. Default: false.
{ "linter": { "rules": { "nursery": { "useSvelteKitResolve": { "level": "on", "options": { "ignoreGoto": true } } } } }}import { goto } from "$app/navigation";
goto("/foo");ignorePushState
Section titled “ignorePushState”Whether to ignore all pushState() calls. Default: false.
{ "linter": { "rules": { "nursery": { "useSvelteKitResolve": { "level": "on", "options": { "ignorePushState": true } } } } }}import { pushState } from "$app/navigation";
pushState("/foo", {});ignoreReplaceState
Section titled “ignoreReplaceState”Whether to ignore all replaceState() calls. Default: false.
{ "linter": { "rules": { "nursery": { "useSvelteKitResolve": { "level": "on", "options": { "ignoreReplaceState": true } } } } }}import { replaceState } from "$app/navigation";
replaceState("/foo", {});References
Section titled “References”Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.