pageClass | sidebarDepth | title | description | since |
---|---|---|---|---|
rule-details |
0 |
svelte/no-goto-without-base |
disallow using goto() without the base path |
v2.36.0-next.9 |
disallow using goto() without the base path
This rule reports navigation using SvelteKit's goto()
function without prefixing a relative URL with the base path. If a non-prefixed relative URL is used for navigation, the goto
function navigates away from the base path, which is usually not what you wanted to do (for external URLs, window.location = url
should be used instead).
<script>
/* eslint svelte/no-goto-without-base: "error" */
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { base as baseAlias } from '$app/paths';
// ✓ GOOD
goto(base + '/foo/');
goto(`${base}/foo/`);
goto(baseAlias + '/foo/');
goto(`${baseAlias}/foo/`);
goto('https://localhost/foo/');
// ✗ BAD
goto('/foo');
goto('/foo/' + base);
goto(`/foo/${base}`);
</script>
Nothing.
This rule was introduced in eslint-plugin-svelte v2.36.0-next.9