Skip to content

Latest commit

 

History

History
61 lines (40 loc) · 1.69 KB

no-goto-without-base.md

File metadata and controls

61 lines (40 loc) · 1.69 KB
pageClass sidebarDepth title description
rule-details
0
svelte/no-goto-without-base
disallow using goto() without the base path

svelte/no-goto-without-base

disallow using goto() without the base path

  • This rule has not been released yet.

📖 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

🔍 Implementation