@solidjs/router 0.13.3 → 0.13.5
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 +1 -1
- package/dist/components.jsx +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/routers/HashRouter.js +1 -1
- package/dist/routing.d.ts +5 -5
- package/dist/routing.js +1 -1
- package/dist/types.d.ts +4 -4
- package/dist/utils.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -868,7 +868,7 @@ return <div classList={{ active: Boolean(match()) }} />;
|
|
|
868
868
|
For example if you stored breadcrumbs on your route definition you could retrieve them like so:
|
|
869
869
|
```js
|
|
870
870
|
const matches = useCurrentMatches();
|
|
871
|
-
const breadcrumbs = createMemo(() => matches.map(m => m.route.info.breadcrumb))
|
|
871
|
+
const breadcrumbs = createMemo(() => matches().map(m => m.route.info.breadcrumb))
|
|
872
872
|
```
|
|
873
873
|
|
|
874
874
|
### useBeforeLeave
|
package/dist/components.jsx
CHANGED
|
@@ -20,7 +20,7 @@ export function A(props) {
|
|
|
20
20
|
return [false, false];
|
|
21
21
|
const path = normalizePath(to_.split(/[?#]/, 1)[0]).toLowerCase();
|
|
22
22
|
const loc = normalizePath(location.pathname).toLowerCase();
|
|
23
|
-
return [props.end ? path === loc : loc.startsWith(path), path === loc];
|
|
23
|
+
return [props.end ? path === loc : loc.startsWith(path + "/") || loc === path, path === loc];
|
|
24
24
|
});
|
|
25
25
|
return (<a {...rest} href={href() || props.href} state={JSON.stringify(props.state)} classList={{
|
|
26
26
|
...(props.class && { [props.class]: true }),
|
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export * from "./lifecycle.js";
|
|
|
4
4
|
export { useHref, useIsRouting, useLocation, useMatch, useCurrentMatches, useNavigate, useParams, useResolvedPath, useSearchParams, useBeforeLeave, } from "./routing.js";
|
|
5
5
|
export { mergeSearchString as _mergeSearchString } from "./utils.js";
|
|
6
6
|
export * from "./data/index.js";
|
|
7
|
-
export type { Location, LocationChange, NavigateOptions, Navigator, OutputMatch, Params, RouteSectionProps, RouteLoadFunc, RouteLoadFuncArgs, RouteDefinition, RouterIntegration, RouterUtils, SetParams, BeforeLeaveEventArgs } from "./types.js";
|
|
7
|
+
export type { Location, LocationChange, MatchFilter, MatchFilters, NavigateOptions, Navigator, OutputMatch, Params, PathMatch, RouteSectionProps, RouteLoadFunc, RouteLoadFuncArgs, RouteDefinition, RouteDescription, RouteMatch, RouterIntegration, RouterUtils, SetParams, BeforeLeaveEventArgs } from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -256,7 +256,7 @@ const useMatch = (path, matchFilters) => {
|
|
|
256
256
|
}
|
|
257
257
|
});
|
|
258
258
|
};
|
|
259
|
-
const useCurrentMatches = () => useRouter().matches
|
|
259
|
+
const useCurrentMatches = () => useRouter().matches;
|
|
260
260
|
const useParams = () => useRouter().params;
|
|
261
261
|
const useSearchParams = () => {
|
|
262
262
|
const location = useLocation();
|
|
@@ -1374,7 +1374,7 @@ function HashRouter(props) {
|
|
|
1374
1374
|
if (replace) {
|
|
1375
1375
|
window.history.replaceState(keepDepth(state), "", "#" + value);
|
|
1376
1376
|
} else {
|
|
1377
|
-
window.
|
|
1377
|
+
window.history.pushState(state, "", "#" + value);
|
|
1378
1378
|
}
|
|
1379
1379
|
const hashIndex = value.indexOf("#");
|
|
1380
1380
|
const hash = hashIndex >= 0 ? value.slice(hashIndex + 1) : "";
|
|
@@ -1466,7 +1466,7 @@ function A(props) {
|
|
|
1466
1466
|
if (to_ === undefined) return [false, false];
|
|
1467
1467
|
const path = normalizePath(to_.split(/[?#]/, 1)[0]).toLowerCase();
|
|
1468
1468
|
const loc = normalizePath(location.pathname).toLowerCase();
|
|
1469
|
-
return [props.end ? path === loc : loc.startsWith(path), path === loc];
|
|
1469
|
+
return [props.end ? path === loc : loc.startsWith(path + "/") || loc === path, path === loc];
|
|
1470
1470
|
});
|
|
1471
1471
|
return (() => {
|
|
1472
1472
|
const _el$ = _tmpl$();
|
|
@@ -22,7 +22,7 @@ export function HashRouter(props) {
|
|
|
22
22
|
window.history.replaceState(keepDepth(state), "", "#" + value);
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
|
-
window.
|
|
25
|
+
window.history.pushState(state, "", "#" + value);
|
|
26
26
|
}
|
|
27
27
|
const hashIndex = value.indexOf("#");
|
|
28
28
|
const hash = hashIndex >= 0 ? value.slice(hashIndex + 1) : "";
|
package/dist/routing.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSX, Accessor } from "solid-js";
|
|
2
|
-
import type { BeforeLeaveEventArgs, Branch, Intent, Location, MatchFilters, NavigateOptions, Navigator, Params,
|
|
2
|
+
import type { BeforeLeaveEventArgs, Branch, Intent, Location, MatchFilters, NavigateOptions, Navigator, Params, RouteDescription, RouteContext, RouteDefinition, RouteMatch, RouterContext, RouterIntegration, SetParams } from "./types.js";
|
|
3
3
|
export declare const RouterContextObj: import("solid-js").Context<RouterContext | undefined>;
|
|
4
4
|
export declare const RouteContextObj: import("solid-js").Context<RouteContext | undefined>;
|
|
5
5
|
export declare const useRouter: () => RouterContext;
|
|
@@ -10,13 +10,13 @@ export declare const useNavigate: () => Navigator;
|
|
|
10
10
|
export declare const useLocation: <S = unknown>() => Location<S>;
|
|
11
11
|
export declare const useIsRouting: () => () => boolean;
|
|
12
12
|
export declare const useMatch: <S extends string>(path: () => S, matchFilters?: MatchFilters<S> | undefined) => Accessor<import("./types.js").PathMatch | undefined>;
|
|
13
|
-
export declare const useCurrentMatches: () => RouteMatch[];
|
|
13
|
+
export declare const useCurrentMatches: () => () => RouteMatch[];
|
|
14
14
|
export declare const useParams: <T extends Params>() => T;
|
|
15
15
|
export declare const useSearchParams: <T extends Params>() => [Partial<T>, (params: SetParams, options?: Partial<NavigateOptions>) => void];
|
|
16
16
|
export declare const useBeforeLeave: (listener: (e: BeforeLeaveEventArgs) => void) => void;
|
|
17
|
-
export declare function createRoutes(routeDef: RouteDefinition, base?: string):
|
|
18
|
-
export declare function createBranch(routes:
|
|
19
|
-
export declare function createBranches(routeDef: RouteDefinition | RouteDefinition[], base?: string, stack?:
|
|
17
|
+
export declare function createRoutes(routeDef: RouteDefinition, base?: string): RouteDescription[];
|
|
18
|
+
export declare function createBranch(routes: RouteDescription[], index?: number): Branch;
|
|
19
|
+
export declare function createBranches(routeDef: RouteDefinition | RouteDefinition[], base?: string, stack?: RouteDescription[], branches?: Branch[]): Branch[];
|
|
20
20
|
export declare function getRouteMatches(branches: Branch[], location: string): RouteMatch[];
|
|
21
21
|
export declare function createLocation(path: Accessor<string>, state: Accessor<any>): Location;
|
|
22
22
|
export declare function getIntent(): Intent | undefined;
|
package/dist/routing.js
CHANGED
|
@@ -34,7 +34,7 @@ export const useMatch = (path, matchFilters) => {
|
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
|
-
export const useCurrentMatches = () => useRouter().matches
|
|
37
|
+
export const useCurrentMatches = () => useRouter().matches;
|
|
38
38
|
export const useParams = () => useRouter().params;
|
|
39
39
|
export const useSearchParams = () => {
|
|
40
40
|
const location = useLocation();
|
package/dist/types.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ export type RouteLoadFunc<T = unknown> = (args: RouteLoadFuncArgs) => T;
|
|
|
65
65
|
export interface RouteSectionProps<T = unknown> {
|
|
66
66
|
params: Params;
|
|
67
67
|
location: Location;
|
|
68
|
-
data
|
|
68
|
+
data: T;
|
|
69
69
|
children?: JSX.Element;
|
|
70
70
|
}
|
|
71
71
|
export type RouteDefinition<S extends string | string[] = any, T = unknown> = {
|
|
@@ -86,7 +86,7 @@ export interface PathMatch {
|
|
|
86
86
|
path: string;
|
|
87
87
|
}
|
|
88
88
|
export interface RouteMatch extends PathMatch {
|
|
89
|
-
route:
|
|
89
|
+
route: RouteDescription;
|
|
90
90
|
}
|
|
91
91
|
export interface OutputMatch {
|
|
92
92
|
path: string;
|
|
@@ -95,7 +95,7 @@ export interface OutputMatch {
|
|
|
95
95
|
params: Params;
|
|
96
96
|
info?: Record<string, any>;
|
|
97
97
|
}
|
|
98
|
-
export interface
|
|
98
|
+
export interface RouteDescription {
|
|
99
99
|
key: unknown;
|
|
100
100
|
originalPath: string;
|
|
101
101
|
pattern: string;
|
|
@@ -106,7 +106,7 @@ export interface Route {
|
|
|
106
106
|
info?: Record<string, any>;
|
|
107
107
|
}
|
|
108
108
|
export interface Branch {
|
|
109
|
-
routes:
|
|
109
|
+
routes: RouteDescription[];
|
|
110
110
|
score: number;
|
|
111
111
|
matcher: (location: string) => RouteMatch[] | null;
|
|
112
112
|
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MatchFilters, Params, PathMatch,
|
|
1
|
+
import type { MatchFilters, Params, PathMatch, RouteDescription, SetParams } from "./types.ts";
|
|
2
2
|
export declare const mockBase = "http://sr";
|
|
3
3
|
export declare function normalizePath(path: string, omitSlash?: boolean): string;
|
|
4
4
|
export declare function resolvePath(base: string, path: string, from?: string): string | undefined;
|
|
@@ -6,7 +6,7 @@ export declare function invariant<T>(value: T | null | undefined, message: strin
|
|
|
6
6
|
export declare function joinPaths(from: string, to: string): string;
|
|
7
7
|
export declare function extractSearchParams(url: URL): Params;
|
|
8
8
|
export declare function createMatcher<S extends string>(path: S, partial?: boolean, matchFilters?: MatchFilters<S>): (location: string) => PathMatch | null;
|
|
9
|
-
export declare function scoreRoute(route:
|
|
9
|
+
export declare function scoreRoute(route: RouteDescription): number;
|
|
10
10
|
export declare function createMemoObject<T extends Record<string | symbol, unknown>>(fn: () => T): T;
|
|
11
11
|
export declare function mergeSearchString(search: string, params: SetParams): string;
|
|
12
12
|
export declare function expandOptionals(pattern: string): string[];
|