Use this file to discover all available pages before exploring further.
useLocation() returns a Svelte readable store that always reflects the currently matched URL. Whenever the user navigates—whether through a <Link>, the navigate() function, or the browser’s own back/forward controls—the store updates automatically and any component subscribed to it re-renders. Because it relies on Svelte’s getContext, it must be called at the top level of a Svelte component’s <script> block, not inside a plain .ts module or an event handler.
useLocation() uses Svelte’s getContext() under the hood and must be called during component initialisation, i.e. at the top level of a <script> block inside a .svelte file. Calling it inside a function, a $effect, or outside a component will throw a Svelte context error.
useLocation() is the in-component counterpart of the top-level listen() export. Use useLocation() inside Svelte components for reactive, auto-cleaned-up subscriptions. Use listen() in plain TypeScript/JavaScript modules—such as analytics initialization—where Svelte context is not available.
// Works outside a Svelte componentimport { listen } from "svelte5-router";const unlisten = listen(({ location }) => { console.log("Navigated to", location.pathname);});// Call unlisten() when no longer needed