File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818 const { history, scroll, shallow } = options ;
1919
2020 if (browser ) {
21- const url = new URL (location . href );
21+ const url = new URL (page . url );
2222 url .search = renderQueryString (search );
2323
2424 if (shallow ) {
4141 }
4242 },
4343
44- searchParams : () => page .url .searchParams ,
45- getSearchParamsSnapshot : () => page .url .searchParams ,
44+ searchParams : () => new URLSearchParams ( page .url .searchParams ) ,
45+ getSearchParamsSnapshot : () => new URLSearchParams ( page .url .searchParams ) ,
4646 };
4747 </script >
4848
Original file line number Diff line number Diff line change 1+ export const load = ( { url } ) => {
2+ const switchValue = url . searchParams . get ( "switch" ) ;
3+ const query = url . searchParams . get ( "q" ) ;
4+
5+ return {
6+ query,
7+ switch : switchValue ,
8+ time : new Date ( ) ,
9+ } ;
10+ } ;
Original file line number Diff line number Diff line change 11<script lang =" ts" >
2- import { goto } from " $app/navigation" ;
32 import { parseAsBoolean , parseAsString } from " $lib/parsers" ;
43 import { useQueryState } from " $lib/use-query-state.svelte" ;
54
5+ let { data } = $props ();
6+
67 const query = useQueryState (" q" , parseAsString .withDefault (" string-value" ));
78
8- const switchState = useQueryState (" switch" , parseAsBoolean .withDefault (false ));
9+ const switchState = useQueryState (
10+ " switch" ,
11+ parseAsBoolean .withDefault (false ).withOptions ({ shallow: false }),
12+ );
913 </script >
1014
1115<div class =" flex flex-col gap-2" >
1519 placeholder =" Search..."
1620 class =" w-full rounded-md bg-neutral-900 p-2 text-white ring ring-neutral-600"
1721 />
18-
19- <button
20- type =" button"
21- onclick ={() => goto (` ?switch=${! switchState .current } ` )}
22- class =" rounded-md p-2 text-white ring ring-neutral-600
23- {switchState.current ? 'bg-green-500' : 'bg-neutral-900'}"
24- >
25- Switch with goto
26- </button >
27-
2822 <button
2923 type =" button"
3024 class =" rounded-md p-2 text-white ring ring-neutral-600
3327 >
3428 Toggle Switch
3529 </button >
30+
31+ <p >Loader last updated: {data .time .toLocaleTimeString ()}.</p >
32+ <p >Query value from loader: {data .query }</p >
33+ <p >Switch value from loader: {data .switch }</p >
3634</div >
You can’t perform that action at this time.
0 commit comments