@real-router/svelte 0.16.8 → 0.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -2
- package/dist/actions/link.svelte.js +4 -1
- package/dist/components/Link.svelte +38 -14
- package/dist/components/Link.svelte.d.ts +4 -2
- package/dist/composables/useIsActiveRoute.svelte.d.ts +2 -2
- package/dist/composables/useIsActiveRoute.svelte.js +2 -2
- package/dist/dom-utils/index.d.ts +2 -1
- package/dist/dom-utils/index.js +1 -1
- package/dist/dom-utils/link-utils.d.ts +29 -3
- package/dist/dom-utils/link-utils.js +59 -7
- package/dist/dom-utils/scroll-restore.js +5 -1
- package/dist/dom-utils/scroll-spy.js +7 -1
- package/dist/types.d.ts +19 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -183,7 +183,8 @@ Navigation link with automatic active state detection. Uses `$derived` for href
|
|
|
183
183
|
| Prop | Type | Default | Description |
|
|
184
184
|
| ------------------- | --------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------- |
|
|
185
185
|
| `routeName` | `string` | required | Target route name |
|
|
186
|
-
| `routeParams` | `Params` | `undefined` | Route parameters (omitted → `undefined`, shares one active-route source with `useIsActiveRoute(name)`, #776)
|
|
186
|
+
| `routeParams` | `Params` | `undefined` | Route (path) parameters (omitted → `undefined`, shares one active-route source with `useIsActiveRoute(name)`, #776) |
|
|
187
|
+
| `routeSearch` | `SearchParams` | `undefined` | Query (search) parameters for the link's target — parallel to `routeParams` (RFC-4 M2, #1548) |
|
|
187
188
|
| `routeOptions` | `NavigationOptions` | `{}` | Navigation options (replace, etc.) |
|
|
188
189
|
| `class` | `string` | `undefined` | CSS class |
|
|
189
190
|
| `activeClassName` | `string` | `"active"` | Class added when route is active |
|
|
@@ -195,6 +196,17 @@ Navigation link with automatic active state detection. Uses `$derived` for href
|
|
|
195
196
|
|
|
196
197
|
All other props are spread onto the `<a>` element.
|
|
197
198
|
|
|
199
|
+
#### `routeSearch` — query (search) channel
|
|
200
|
+
|
|
201
|
+
```svelte
|
|
202
|
+
<!-- Pagination link with an explicit query channel; active only on ?page=2 -->
|
|
203
|
+
<Link routeName="users" routeSearch={{ page: "2" }} ignoreQueryParams={false}>
|
|
204
|
+
Page 2
|
|
205
|
+
</Link>
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
`routeSearch?: SearchParams` is the query channel of the path/query split (RFC-4 M2, #1548) — parallel to `routeParams` (the path channel). It feeds the URL query string in `href` (forwarded to `buildUrl`/`buildPath`) and, paired with `ignoreQueryParams={false}`, the active-state check.
|
|
209
|
+
|
|
198
210
|
#### `hash` — URL fragment / tab-style UIs
|
|
199
211
|
|
|
200
212
|
```svelte
|
|
@@ -367,7 +379,7 @@ Factory function that creates a low-level action for adding navigation to any el
|
|
|
367
379
|
|
|
368
380
|
The action automatically adds `role="link"` + `tabindex="0"` to non-interactive elements for accessibility (skipping `<a>` / `<button>` which already convey link semantics). It handles click events and Enter key navigation.
|
|
369
381
|
|
|
370
|
-
> **Hash asymmetry vs `<Link hash>`:** `createLinkAction` does **not** accept a `hash` parameter; `<Link hash="x">` does (#532). Use `<Link>` when a hash-aware variant is needed (tab-style UIs, same-route different-fragment navigation through `navigateWithHash`). For pure `use:link` callers, attach a click handler that calls `router.navigate(name, params, { force: true, hash: "x" })` manually if hash control is required.
|
|
382
|
+
> **Hash asymmetry vs `<Link hash>`:** `createLinkAction` does **not** accept a `hash` parameter; `<Link hash="x">` does (#532). Use `<Link>` when a hash-aware variant is needed (tab-style UIs, same-route different-fragment navigation through `navigateWithHash`). For pure `use:link` callers, attach a click handler that calls `router.navigate(name, params, undefined, { force: true, hash: "x" })` manually if hash control is required.
|
|
371
383
|
|
|
372
384
|
## Reactive Primitives
|
|
373
385
|
|
|
@@ -21,7 +21,10 @@ function getDelegation(router) {
|
|
|
21
21
|
let count = 0;
|
|
22
22
|
function navigate(target) {
|
|
23
23
|
router
|
|
24
|
-
.navigate(target.name, target.params ?? EMPTY_PARAMS,
|
|
24
|
+
.navigate(target.name, target.params ?? EMPTY_PARAMS,
|
|
25
|
+
// Slot-shift (RFC-4 M2 / #1548): query channel at position 3 (unused —
|
|
26
|
+
// Link query rides in params), options at position 4.
|
|
27
|
+
undefined, target.options ?? EMPTY_OPTIONS)
|
|
25
28
|
.catch(NOOP);
|
|
26
29
|
}
|
|
27
30
|
function handleClick(evt) {
|
|
@@ -7,14 +7,22 @@
|
|
|
7
7
|
buildHref,
|
|
8
8
|
buildActiveClassName,
|
|
9
9
|
navigateWithHash,
|
|
10
|
+
resolveLinkTarget,
|
|
10
11
|
} from "../dom-utils";
|
|
11
12
|
|
|
12
|
-
import type {
|
|
13
|
+
import type {
|
|
14
|
+
NavigationOptions,
|
|
15
|
+
NavigationTarget,
|
|
16
|
+
Params,
|
|
17
|
+
SearchParams,
|
|
18
|
+
} from "@real-router/core";
|
|
13
19
|
import type { Snippet } from "svelte";
|
|
14
20
|
|
|
15
21
|
let {
|
|
16
22
|
routeName,
|
|
17
23
|
routeParams,
|
|
24
|
+
routeSearch,
|
|
25
|
+
to,
|
|
18
26
|
routeOptions = EMPTY_OPTIONS,
|
|
19
27
|
class: className = undefined,
|
|
20
28
|
activeClassName = "active",
|
|
@@ -26,8 +34,10 @@
|
|
|
26
34
|
onclick: userOnClick = undefined,
|
|
27
35
|
...restProps
|
|
28
36
|
}: {
|
|
29
|
-
routeName
|
|
37
|
+
routeName?: string;
|
|
30
38
|
routeParams?: Params;
|
|
39
|
+
routeSearch?: SearchParams;
|
|
40
|
+
to?: NavigationTarget;
|
|
31
41
|
routeOptions?: NavigationOptions;
|
|
32
42
|
class?: string;
|
|
33
43
|
activeClassName?: string;
|
|
@@ -56,25 +66,35 @@
|
|
|
56
66
|
//
|
|
57
67
|
// Hash-aware active (#532): tab links sharing routeName but differing in
|
|
58
68
|
// hash should only light up the matching variant.
|
|
69
|
+
// Resolve the two prop forms into one channel triple (RFC-4 M2 B2, #1548): a
|
|
70
|
+
// `to` descriptor supersedes the channel props (dev-warn on conflict). Captured
|
|
71
|
+
// at mount for the active source (mirrors the routeName/params capture above).
|
|
72
|
+
// svelte-ignore state_referenced_locally
|
|
73
|
+
const mountTarget = resolveLinkTarget(
|
|
74
|
+
to,
|
|
75
|
+
routeName ?? "",
|
|
76
|
+
routeParams,
|
|
77
|
+
routeSearch,
|
|
78
|
+
);
|
|
79
|
+
|
|
59
80
|
// svelte-ignore state_referenced_locally
|
|
60
81
|
// Active-route state is captured at mount; href remains reactive separately.
|
|
61
82
|
const activeState = useIsActiveRoute(
|
|
62
|
-
|
|
63
|
-
|
|
83
|
+
mountTarget.name,
|
|
84
|
+
mountTarget.params,
|
|
85
|
+
mountTarget.search,
|
|
64
86
|
activeStrict,
|
|
65
87
|
ignoreQueryParams,
|
|
66
88
|
hash,
|
|
67
89
|
);
|
|
68
90
|
|
|
69
91
|
// Navigation/href building need a concrete params object — default here only.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
),
|
|
77
|
-
);
|
|
92
|
+
// `search` stays raw (`undefined` when unset). Reactive resolve for href.
|
|
93
|
+
const href = $derived.by(() => {
|
|
94
|
+
const resolved = resolveLinkTarget(to, routeName ?? "", routeParams, routeSearch);
|
|
95
|
+
|
|
96
|
+
return buildHref(router, resolved.name, resolved.params ?? EMPTY_PARAMS, resolved.search, hash);
|
|
97
|
+
});
|
|
78
98
|
|
|
79
99
|
const finalClassName = $derived(
|
|
80
100
|
buildActiveClassName(activeState.current, activeClassName, className),
|
|
@@ -106,10 +126,14 @@
|
|
|
106
126
|
}
|
|
107
127
|
|
|
108
128
|
evt.preventDefault();
|
|
129
|
+
|
|
130
|
+
const resolved = resolveLinkTarget(to, routeName ?? "", routeParams, routeSearch);
|
|
131
|
+
|
|
109
132
|
navigateWithHash(
|
|
110
133
|
router,
|
|
111
|
-
|
|
112
|
-
|
|
134
|
+
resolved.name,
|
|
135
|
+
resolved.params ?? EMPTY_PARAMS,
|
|
136
|
+
resolved.search,
|
|
113
137
|
hash,
|
|
114
138
|
routeOptions,
|
|
115
139
|
).catch(NOOP);
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type { NavigationOptions, Params } from "@real-router/core";
|
|
1
|
+
import type { NavigationOptions, NavigationTarget, Params, SearchParams } from "@real-router/core";
|
|
2
2
|
import type { Snippet } from "svelte";
|
|
3
3
|
type $$ComponentProps = {
|
|
4
|
-
routeName
|
|
4
|
+
routeName?: string;
|
|
5
5
|
routeParams?: Params;
|
|
6
|
+
routeSearch?: SearchParams;
|
|
7
|
+
to?: NavigationTarget;
|
|
6
8
|
routeOptions?: NavigationOptions;
|
|
7
9
|
class?: string;
|
|
8
10
|
activeClassName?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Params } from "@real-router/core";
|
|
2
|
-
export declare function useIsActiveRoute(routeName: string, params: Params | undefined, strict: boolean, ignoreQueryParams: boolean, hash?: string): {
|
|
1
|
+
import type { Params, SearchParams } from "@real-router/core";
|
|
2
|
+
export declare function useIsActiveRoute(routeName: string, params: Params | undefined, search: SearchParams | undefined, strict: boolean, ignoreQueryParams: boolean, hash?: string): {
|
|
3
3
|
readonly current: boolean;
|
|
4
4
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createActiveSource } from "@real-router/sources";
|
|
2
2
|
import { createReactiveSource } from "../createReactiveSource.svelte";
|
|
3
3
|
import { useRouter } from "./useRouter.svelte";
|
|
4
|
-
export function useIsActiveRoute(routeName, params, strict, ignoreQueryParams, hash) {
|
|
4
|
+
export function useIsActiveRoute(routeName, params, search, strict, ignoreQueryParams, hash) {
|
|
5
5
|
const router = useRouter();
|
|
6
6
|
// The fast/slow decision — and the `routeName !== ""` guard that keeps
|
|
7
7
|
// `useIsActiveRoute("")` in sync with `router.isActiveRoute("")` (a misused
|
|
@@ -9,5 +9,5 @@ export function useIsActiveRoute(routeName, params, strict, ignoreQueryParams, h
|
|
|
9
9
|
// builder (#1099 landed the fast path inline here; #1427 folded it into the
|
|
10
10
|
// shared builder). `createReactiveSource` bridges either path — the selector-
|
|
11
11
|
// backed fast source or the per-link slow source — to Svelte reactivity.
|
|
12
|
-
return createReactiveSource(createActiveSource(router, routeName, params, strict, ignoreQueryParams, hash));
|
|
12
|
+
return createReactiveSource(createActiveSource(router, routeName, params, search, strict, ignoreQueryParams, hash));
|
|
13
13
|
}
|
|
@@ -3,7 +3,8 @@ export { createRouteAnnouncer } from "./route-announcer.js";
|
|
|
3
3
|
export { createScrollRestoration } from "./scroll-restore.js";
|
|
4
4
|
export { createScrollSpy } from "./scroll-spy.js";
|
|
5
5
|
export { createViewTransitions } from "./view-transitions.js";
|
|
6
|
-
export { shouldNavigate, buildHref, buildActiveClassName, navigateWithHash, shallowEqual, applyLinkA11y, } from "./link-utils.js";
|
|
6
|
+
export { shouldNavigate, buildHref, buildActiveClassName, navigateWithHash, resolveLinkTarget, shallowEqual, applyLinkA11y, } from "./link-utils.js";
|
|
7
|
+
export type { ResolvedLinkTarget } from "./link-utils.js";
|
|
7
8
|
export type { RouteAnnouncerOptions } from "./route-announcer.js";
|
|
8
9
|
export type { ScrollRestorationOptions, ScrollRestorationMode, } from "./scroll-restore.js";
|
|
9
10
|
export type { ScrollSpy, ScrollSpyOptions } from "./scroll-spy.js";
|
package/dist/dom-utils/index.js
CHANGED
|
@@ -3,4 +3,4 @@ export { createRouteAnnouncer } from "./route-announcer.js";
|
|
|
3
3
|
export { createScrollRestoration } from "./scroll-restore.js";
|
|
4
4
|
export { createScrollSpy } from "./scroll-spy.js";
|
|
5
5
|
export { createViewTransitions } from "./view-transitions.js";
|
|
6
|
-
export { shouldNavigate, buildHref, buildActiveClassName, navigateWithHash, shallowEqual, applyLinkA11y, } from "./link-utils.js";
|
|
6
|
+
export { shouldNavigate, buildHref, buildActiveClassName, navigateWithHash, resolveLinkTarget, shallowEqual, applyLinkA11y, } from "./link-utils.js";
|
|
@@ -1,4 +1,30 @@
|
|
|
1
|
-
import type { NavigationOptions, Params, Router, State } from "@real-router/core";
|
|
1
|
+
import type { NavigationOptions, NavigationTarget, Params, Router, SearchParams, State } from "@real-router/core";
|
|
2
|
+
/**
|
|
3
|
+
* Resolved navigation channels for a `<Link>` — the single `{ name, params,
|
|
4
|
+
* search }` shape every adapter feeds into `buildHref` / `navigateWithHash` /
|
|
5
|
+
* the active-route source, regardless of which prop form the consumer used.
|
|
6
|
+
*/
|
|
7
|
+
export interface ResolvedLinkTarget {
|
|
8
|
+
name: string;
|
|
9
|
+
params: Params | undefined;
|
|
10
|
+
search: SearchParams | undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Collapses a `<Link>`'s two prop forms (RFC-4 M2 B2, #1548) into one channel
|
|
14
|
+
* triple:
|
|
15
|
+
*
|
|
16
|
+
* - **Descriptor** — `to={{ name, params?, search? }}` (a `NavigationTarget`).
|
|
17
|
+
* - **Channel props** — `routeName` + `routeParams?` + `routeSearch?`.
|
|
18
|
+
*
|
|
19
|
+
* The forms are mutually exclusive: the TS union on each adapter's `LinkProps`
|
|
20
|
+
* rejects mixing them at compile time, and this helper is the runtime backstop —
|
|
21
|
+
* when `to` is present it **wins**, and a `dev`-visible `console.warn` fires if
|
|
22
|
+
* channel props were also supplied (a JS consumer, an object spread, or an
|
|
23
|
+
* adapter without a strict union can still slip both through). `routeOptions` /
|
|
24
|
+
* `hash` are separate props under BOTH forms (hash is not part of
|
|
25
|
+
* `NavigationTarget` — #532), so they are resolved by the caller, not here.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveLinkTarget(to: NavigationTarget | undefined, routeName: string, routeParams: Params | undefined, routeSearch: SearchParams | undefined): ResolvedLinkTarget;
|
|
2
28
|
export declare function shouldNavigate(evt: MouseEvent): boolean;
|
|
3
29
|
/**
|
|
4
30
|
* Builds an href for a `<Link>` element.
|
|
@@ -13,8 +39,8 @@ export declare function shouldNavigate(evt: MouseEvent): boolean;
|
|
|
13
39
|
* passed positionally to mirror `navigateWithHash(router, name, params, hash)`
|
|
14
40
|
* (#1442). Previous 3-arg call sites continue to work unchanged.
|
|
15
41
|
*/
|
|
16
|
-
export declare function buildHref(router: Router, routeName: string, routeParams: Params, hash?: string): string | undefined;
|
|
17
|
-
export declare function navigateWithHash(router: Router, routeName: string, routeParams: Params, hash: string | undefined, extraOptions?: NavigationOptions): Promise<State>;
|
|
42
|
+
export declare function buildHref(router: Router, routeName: string, routeParams: Params, routeSearch?: SearchParams, hash?: string): string | undefined;
|
|
43
|
+
export declare function navigateWithHash(router: Router, routeName: string, routeParams: Params, routeSearch: SearchParams | undefined, hash: string | undefined, extraOptions?: NavigationOptions): Promise<State>;
|
|
18
44
|
export declare function buildActiveClassName(isActive: boolean, activeClassName: string | undefined, baseClassName: string | undefined): string | undefined;
|
|
19
45
|
/**
|
|
20
46
|
* One-level structural equality using `Object.is` per key.
|
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collapses a `<Link>`'s two prop forms (RFC-4 M2 B2, #1548) into one channel
|
|
3
|
+
* triple:
|
|
4
|
+
*
|
|
5
|
+
* - **Descriptor** — `to={{ name, params?, search? }}` (a `NavigationTarget`).
|
|
6
|
+
* - **Channel props** — `routeName` + `routeParams?` + `routeSearch?`.
|
|
7
|
+
*
|
|
8
|
+
* The forms are mutually exclusive: the TS union on each adapter's `LinkProps`
|
|
9
|
+
* rejects mixing them at compile time, and this helper is the runtime backstop —
|
|
10
|
+
* when `to` is present it **wins**, and a `dev`-visible `console.warn` fires if
|
|
11
|
+
* channel props were also supplied (a JS consumer, an object spread, or an
|
|
12
|
+
* adapter without a strict union can still slip both through). `routeOptions` /
|
|
13
|
+
* `hash` are separate props under BOTH forms (hash is not part of
|
|
14
|
+
* `NavigationTarget` — #532), so they are resolved by the caller, not here.
|
|
15
|
+
*/
|
|
16
|
+
export function resolveLinkTarget(to, routeName, routeParams, routeSearch) {
|
|
17
|
+
if (to !== undefined) {
|
|
18
|
+
if (routeName !== "" ||
|
|
19
|
+
routeParams !== undefined ||
|
|
20
|
+
routeSearch !== undefined) {
|
|
21
|
+
console.warn("[real-router] <Link> received both `to` and channel props " +
|
|
22
|
+
"(routeName / routeParams / routeSearch). `to` wins; the channel " +
|
|
23
|
+
"props are ignored. Use one form or the other.");
|
|
24
|
+
}
|
|
25
|
+
return { name: to.name, params: to.params, search: to.search };
|
|
26
|
+
}
|
|
27
|
+
return { name: routeName, params: routeParams, search: routeSearch };
|
|
28
|
+
}
|
|
1
29
|
export function shouldNavigate(evt) {
|
|
2
30
|
return (evt.button === 0 &&
|
|
3
31
|
!evt.metaKey &&
|
|
@@ -38,7 +66,7 @@ function encodeFragmentInline(decoded) {
|
|
|
38
66
|
* passed positionally to mirror `navigateWithHash(router, name, params, hash)`
|
|
39
67
|
* (#1442). Previous 3-arg call sites continue to work unchanged.
|
|
40
68
|
*/
|
|
41
|
-
export function buildHref(router, routeName, routeParams, hash) {
|
|
69
|
+
export function buildHref(router, routeName, routeParams, routeSearch, hash) {
|
|
42
70
|
try {
|
|
43
71
|
let normHash;
|
|
44
72
|
if (hash !== undefined) {
|
|
@@ -46,7 +74,11 @@ export function buildHref(router, routeName, routeParams, hash) {
|
|
|
46
74
|
}
|
|
47
75
|
const buildUrl = router.buildUrl;
|
|
48
76
|
if (buildUrl) {
|
|
49
|
-
const url = buildUrl(routeName, routeParams,
|
|
77
|
+
const url = buildUrl(routeName, routeParams,
|
|
78
|
+
// Query channel at position 3 (RFC-4 M2 / #1548) — from the `routeSearch`
|
|
79
|
+
// prop; hash options at position 4. `undefined` when the link has no
|
|
80
|
+
// `routeSearch` (its query, if any, still rides in routeParams).
|
|
81
|
+
routeSearch, normHash === undefined ? undefined : { hash: normHash });
|
|
50
82
|
// Accept only non-empty strings. The BuildUrlFn type contract is
|
|
51
83
|
// `string | undefined`, but defensive against:
|
|
52
84
|
// - `""` (empty string) → would render `<a href="">`, which resolves
|
|
@@ -58,7 +90,7 @@ export function buildHref(router, routeName, routeParams, hash) {
|
|
|
58
90
|
return url;
|
|
59
91
|
}
|
|
60
92
|
}
|
|
61
|
-
const path = router.buildPath(routeName, routeParams);
|
|
93
|
+
const path = router.buildPath(routeName, routeParams, routeSearch);
|
|
62
94
|
// Symmetric to the buildUrl guard above (#S1 audit, Invariant 12).
|
|
63
95
|
// `router.buildPath` is typed `string`, but defends against:
|
|
64
96
|
// - `""` (empty string) — would render `<a href="">`, which resolves
|
|
@@ -76,14 +108,32 @@ export function buildHref(router, routeName, routeParams, hash) {
|
|
|
76
108
|
return undefined;
|
|
77
109
|
}
|
|
78
110
|
}
|
|
79
|
-
export function navigateWithHash(router, routeName, routeParams, hash, extraOptions) {
|
|
111
|
+
export function navigateWithHash(router, routeName, routeParams, routeSearch, hash, extraOptions) {
|
|
80
112
|
const opts = { ...extraOptions };
|
|
81
113
|
if (hash !== undefined) {
|
|
82
114
|
opts.hash = hash;
|
|
83
115
|
}
|
|
84
116
|
const current = router.getState();
|
|
85
|
-
|
|
86
|
-
|
|
117
|
+
// "Does this link point at where we already are?" is a question the router
|
|
118
|
+
// owns, and asking it here by hand got two things wrong at once (#1555).
|
|
119
|
+
//
|
|
120
|
+
// The hand-rolled version compared with `Object.is` per key, so a link writing
|
|
121
|
+
// `routeSearch={{ page: "2" }}` never matched a state parsed from `?page=2`,
|
|
122
|
+
// where the value is the NUMBER 2 — the bypass silently did not fire, core
|
|
123
|
+
// rejected the navigation as SAME_STATES, and `<Link hash>` looked dead. The
|
|
124
|
+
// predicate carries the provenance-tolerant comparison (#1554) that makes the
|
|
125
|
+
// two forms equal because they print the same URL.
|
|
126
|
+
//
|
|
127
|
+
// It also compared the caller's whole `routeParams` bag against `state.params`,
|
|
128
|
+
// which stopped meaning anything once the channels split (#1548) — the
|
|
129
|
+
// predicate applies the channel rule instead of re-deriving it.
|
|
130
|
+
//
|
|
131
|
+
// `strictEquality: true` — a link to a PARENT route is a different location, so
|
|
132
|
+
// the hierarchical arm must not match. `ignoreQueryParams: false` — the query is
|
|
133
|
+
// part of the location here; ignoring it would fire the bypass across a real
|
|
134
|
+
// query change and let `force: true` smuggle it through as a hash change.
|
|
135
|
+
if (current !== undefined &&
|
|
136
|
+
router.isActiveRoute(routeName, routeParams, routeSearch ?? current.search, true, false)) {
|
|
87
137
|
const currentHash = current.context?.url?.hash ??
|
|
88
138
|
"";
|
|
89
139
|
const newHash = hash ?? currentHash;
|
|
@@ -92,7 +142,9 @@ export function navigateWithHash(router, routeName, routeParams, hash, extraOpti
|
|
|
92
142
|
opts.hashChange = true;
|
|
93
143
|
}
|
|
94
144
|
}
|
|
95
|
-
|
|
145
|
+
// Query channel at position 3 (RFC-4 M2 / #1548) — from the `routeSearch`
|
|
146
|
+
// prop; opts at position 4. `undefined` when the link has no `routeSearch`.
|
|
147
|
+
return router.navigate(routeName, routeParams, routeSearch, opts);
|
|
96
148
|
}
|
|
97
149
|
// Match-any-whitespace regex shared across calls. RegExp literals at
|
|
98
150
|
// call-site recompile in some engines; lifting it avoids that microcost
|
|
@@ -338,7 +338,11 @@ export function keyOf(state) {
|
|
|
338
338
|
if (cached !== undefined) {
|
|
339
339
|
return cached;
|
|
340
340
|
}
|
|
341
|
-
|
|
341
|
+
// Key over BOTH channels — path params AND query (RFC-4 M2 / #1548). Merged
|
|
342
|
+
// (not `params:search`) so a query-less route keeps its v1 key shape
|
|
343
|
+
// (`name:{}`), and an unserializable value (BigInt / cyclic) in EITHER channel
|
|
344
|
+
// still throws in `canonicalJson` → `safeKeyOf` drops+warns.
|
|
345
|
+
const key = `${state.name}:${canonicalJson({ ...state.params, ...state.search })}`;
|
|
342
346
|
KEY_CACHE.set(state, key);
|
|
343
347
|
return key;
|
|
344
348
|
}
|
|
@@ -434,7 +434,13 @@ export function createScrollSpy(router, options) {
|
|
|
434
434
|
// changes microtask schedule and breaks "spy continues after rejection".
|
|
435
435
|
selfEmitting = true;
|
|
436
436
|
router
|
|
437
|
-
|
|
437
|
+
// Both channels of the CURRENT state, not just the path bag (RFC-4 M2 /
|
|
438
|
+
// #1548): this is a same-route re-navigation to move the hash, so
|
|
439
|
+
// whatever query the user is already looking at has to survive it.
|
|
440
|
+
// Passing `undefined` in slot 3 dropped it — scrolling a page at
|
|
441
|
+
// `/docs?tab=api` silently rewrote the URL to `/docs`. Options stay at
|
|
442
|
+
// slot 4.
|
|
443
|
+
.navigate(state.name, state.params, state.search, opts)
|
|
438
444
|
.catch(() => {
|
|
439
445
|
// Fire-and-forget — suppress expected rejections (concurrent
|
|
440
446
|
// navigate, router stopped, etc.) consistent with `<Link>` adapter
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NavigationOptions, Navigator, Params, State } from "@real-router/core";
|
|
1
|
+
import type { NavigationOptions, NavigationTarget, Navigator, Params, SearchParams, State } from "@real-router/core";
|
|
2
2
|
import type { Snippet } from "svelte";
|
|
3
3
|
export interface RouteContext<P extends Params = Params> {
|
|
4
4
|
readonly navigator: Navigator;
|
|
@@ -21,8 +21,25 @@ export interface LinkProps<P extends Params = Params> {
|
|
|
21
21
|
* `aria-*`, `data-*`, `id`, `title`, and any other native attributes.
|
|
22
22
|
*/
|
|
23
23
|
readonly [key: string]: unknown;
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Route name (channel form). Optional because the descriptor form (`to`)
|
|
26
|
+
* omits it. The two forms are mutually exclusive — enforced at runtime by
|
|
27
|
+
* `resolveLinkTarget` (dev-warn on conflict, `to` wins). Svelte's index
|
|
28
|
+
* signature above precludes a strict never-union, so the exclusion is a
|
|
29
|
+
* runtime contract here (react/preact/solid enforce it in the type).
|
|
30
|
+
*/
|
|
31
|
+
readonly routeName?: string;
|
|
25
32
|
readonly routeParams?: P;
|
|
33
|
+
/**
|
|
34
|
+
* Query (search) params for the link's target (RFC-4 M2, #1548) — parallel to
|
|
35
|
+
* `routeParams`, the path/query split's view-layer channel.
|
|
36
|
+
*/
|
|
37
|
+
readonly routeSearch?: SearchParams;
|
|
38
|
+
/**
|
|
39
|
+
* Descriptor form (RFC-4 M2 B2, #1548): `to={{ name, params?, search? }}` —
|
|
40
|
+
* mutually exclusive with the channel props above.
|
|
41
|
+
*/
|
|
42
|
+
readonly to?: NavigationTarget<P>;
|
|
26
43
|
readonly routeOptions?: NavigationOptions;
|
|
27
44
|
readonly class?: string;
|
|
28
45
|
readonly activeClassName?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@real-router/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Svelte 5 integration for Real-Router",
|
|
6
6
|
"svelte": "./dist/index.js",
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"license": "MIT",
|
|
49
49
|
"sideEffects": false,
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@real-router/core": "^0.
|
|
51
|
+
"@real-router/core": "^0.82.1",
|
|
52
52
|
"@real-router/route-utils": "^0.3.0",
|
|
53
|
-
"@real-router/sources": "^0.
|
|
53
|
+
"@real-router/sources": "^0.13.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@sveltejs/package": "2.5.8",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"svelte": "~5.56.4",
|
|
64
64
|
"svelte-check": "4.6.0",
|
|
65
65
|
"svelte-eslint-parser": "1.8.0",
|
|
66
|
-
"@real-router/browser-plugin": "^0.
|
|
66
|
+
"@real-router/browser-plugin": "^0.19.0"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"svelte": ">=5.7.0"
|