Sveltekit page store

How to use the sveltekit page store to access url parameters

Table of Contents

Please use app/state if you are using Svelte 5

import { page } from '$app/stores';
$: name = $page.url.searchParams.get('name');

// name = Thomas
import { page } from '$app/stores';
$: slug = $page.params.id;

// url: /snippets/[id] => slug = value of id
import { page } from '$app/stores';
$: path = $page.url.pathname;

// path = /test