Svelte · Junior · Question 72 of 76

How do you read the current URL or route params in a SvelteKit component?

<script>
  import { page } from "$app/state";
</script>

<p>{page.url.pathname}</p>

Explanation

$app/state gives reactive values. $app/stores was the old store-based API; it was deprecated and removed in SvelteKit 3.

Further reading

Problem with a question

Svelte · Junior · question 72

Test yourself

Take the Svelte · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz