-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Motivation
- This package is very close to complete the feature as-is right now.
- Provides developers a unified way of doing it that will work with Sveltekit as well (via
@svelte-router/kit).
Specification
The idea here is to obtain a reactive value of any search parameter value. This router's global location object already has this: location.url.searchParams is an instance of SvelteURLSearchParams. So how do we write? What happens to history state?
Proposal
Let's not encourage people to write directly using location. Instead, let's provide simple API to create reactive, writable stores for a particular search parameter.
searchParamStore
This would be the function that creates the reactive store. It will initialize as most people would do it: With the search parameter name and an initial value. It would spit out a class instance with the reactive value internally calculated as $derived(location.url.searchParams.get(key)). Setting it, on the other hand, would trigger navigation in the sense that it would push or replace the current History API entry using location.navigate().
We should complete the store configuration by allowing consumers the ability to configure this call to location.navigate().
This should provide a clean way for using search parameters as storage without conflicting with the router that works on Svelte and Sveltekit.