Skip to content

Latest commit

 

History

History
62 lines (41 loc) · 1.79 KB

no-goto-without-base.md

File metadata and controls

62 lines (41 loc) · 1.79 KB
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

svelte/no-goto-without-base

disallow using goto() without the base path

📖 Rule Details

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>

🔧 Options

Nothing.

📚 Further Reading

🚀 Version

This rule was introduced in eslint-plugin-svelte v2.36.0-next.9

🔍 Implementation