Skip to content

Commit 89d3bb2

Browse files
committed
docs(no-goto-without-base): documented the rule
1 parent c68344a commit 89d3bb2

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

docs/rules/no-goto-without-base.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
pageClass: 'rule-details'
3+
sidebarDepth: 0
4+
title: 'svelte/no-goto-without-base'
5+
description: 'disallow using goto() without the base path'
6+
---
7+
8+
# svelte/no-goto-without-base
9+
10+
> disallow using goto() without the base path
11+
12+
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> **_This rule has not been released yet._** </badge>
13+
14+
## :book: Rule Details
15+
16+
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).
17+
18+
<ESLintCodeBlock>
19+
20+
<!--eslint-skip-->
21+
22+
```svelte
23+
<script>
24+
/* eslint svelte/no-goto-without-base: "error" */
25+
26+
import { goto } from '$app/navigation';
27+
import { base } from '$app/paths';
28+
import { base as baseAlias } from '$app/paths';
29+
30+
// ✓ GOOD
31+
goto(base + '/foo/');
32+
goto(`${base}/foo/`);
33+
34+
goto(baseAlias + '/foo/');
35+
goto(`${baseAlias}/foo/`);
36+
37+
goto('https://localhost/foo/');
38+
39+
// ✗ BAD
40+
goto('/foo');
41+
42+
goto('/foo/' + base);
43+
goto(`/foo/${base}`);
44+
</script>
45+
46+
47+
```
48+
49+
</ESLintCodeBlock>
50+
51+
## :wrench: Options
52+
53+
Nothing.
54+
55+
## :books: Further Reading
56+
57+
- [`goto()` documentation](https://kit.svelte.dev/docs/modules#$app-navigation-goto)
58+
- [`base` documentation](https://kit.svelte.dev/docs/modules#$app-paths-base)
59+
60+
## :mag: Implementation
61+
62+
- [Rule source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/src/rules/no-goto-without-base.ts)
63+
- [Test source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/tests/src/rules/no-goto-without-base.ts)

0 commit comments

Comments
 (0)