@solidjs/router 2.0.0-next.37 → 2.0.0-next.38

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/dist/utils.d.ts CHANGED
@@ -15,19 +15,20 @@ export declare const comparablePath: (path: string) => string;
15
15
  */
16
16
  export declare function isUnderBase(pathname: string, base: string): boolean;
17
17
  /**
18
- * The link-state rule shared by claimed anchors and `useLinkState`, given
19
- * the location and a link's already-resolved target (path, optional query
20
- * and hash):
18
+ * The link-state rule shared by claimed anchors and `useLinkState`, bound to
19
+ * a location so links matched against the same one share its parse. The
20
+ * returned matcher takes a link's already-resolved target (path, optional
21
+ * query and hash):
21
22
  *
22
23
  * - `current` — same pathname and same query (parameter order and hash aside)
23
24
  * - `active` — same pathname or one under it; the router's root (`base`, or
24
25
  * `/` without one) only matches exactly, since it is a prefix of every
25
26
  * page. `end` makes every link exact-only.
26
27
  */
27
- export declare function matchLink(location: {
28
+ export declare function linkMatcher({ pathname, search }: {
28
29
  pathname: string;
29
30
  search: string;
30
- }, target: string | undefined, base: string, end?: boolean): {
31
+ }, base: string, end?: boolean): (target: string | undefined) => {
31
32
  active: boolean;
32
33
  current: boolean;
33
34
  };
package/dist/utils.js CHANGED
@@ -32,26 +32,30 @@ const comparableQuery = (search) => {
32
32
  return params.toString();
33
33
  };
34
34
  /**
35
- * The link-state rule shared by claimed anchors and `useLinkState`, given
36
- * the location and a link's already-resolved target (path, optional query
37
- * and hash):
35
+ * The link-state rule shared by claimed anchors and `useLinkState`, bound to
36
+ * a location so links matched against the same one share its parse. The
37
+ * returned matcher takes a link's already-resolved target (path, optional
38
+ * query and hash):
38
39
  *
39
40
  * - `current` — same pathname and same query (parameter order and hash aside)
40
41
  * - `active` — same pathname or one under it; the router's root (`base`, or
41
42
  * `/` without one) only matches exactly, since it is a prefix of every
42
43
  * page. `end` makes every link exact-only.
43
44
  */
44
- export function matchLink(location, target, base, end) {
45
- if (target === undefined)
46
- return { active: false, current: false };
47
- const loc = comparablePath(location.pathname);
48
- const path = comparablePath(target);
49
- const exact = loc === path;
50
- const hashless = target.split("#", 1)[0];
51
- const q = hashless.indexOf("?");
52
- return {
53
- active: exact || (!end && path !== "" && path !== comparablePath(base) && loc.startsWith(path + "/")),
54
- current: exact && comparableQuery(location.search) === comparableQuery(q < 0 ? "" : hashless.slice(q))
45
+ export function linkMatcher({ pathname, search }, base, end) {
46
+ const loc = comparablePath(pathname);
47
+ const root = comparablePath(base);
48
+ return (target) => {
49
+ if (target === undefined)
50
+ return { active: false, current: false };
51
+ const path = comparablePath(target);
52
+ const exact = loc === path;
53
+ const hashless = target.split("#", 1)[0];
54
+ const q = hashless.indexOf("?");
55
+ return {
56
+ active: exact || (!end && path !== "" && path !== root && loc.startsWith(path + "/")),
57
+ current: exact && comparableQuery(search) === comparableQuery(q < 0 ? "" : hashless.slice(q))
58
+ };
55
59
  };
56
60
  }
57
61
  export function resolvePath(base, path, from) {
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "Ryan Turnquist"
7
7
  ],
8
8
  "license": "MIT",
9
- "version": "2.0.0-next.37",
9
+ "version": "2.0.0-next.38",
10
10
  "homepage": "https://github.com/solidjs/solid-router#readme",
11
11
  "repository": {
12
12
  "type": "git",