@solidjs/router 0.10.2 → 0.10.3
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/index.d.ts +1 -1
- package/dist/index.js +18 -2
- package/dist/routers/components.d.ts +1 -0
- package/dist/routers/components.jsx +12 -0
- package/dist/routing.js +3 -2
- package/dist/types.d.ts +6 -12
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export * from "./lifecycle";
|
|
|
4
4
|
export { useHref, useIsRouting, useLocation, useMatch, useNavigate, useParams, useResolvedPath, useSearchParams, useBeforeLeave, } from "./routing";
|
|
5
5
|
export { mergeSearchString as _mergeSearchString } from "./utils";
|
|
6
6
|
export * from "./data";
|
|
7
|
-
export type { Location, LocationChange, NavigateOptions, Navigator, OutputMatch, Params, RouteSectionProps, RouteLoadFunc, RouteLoadFuncArgs, RouteDefinition, RouterIntegration,
|
|
7
|
+
export type { Location, LocationChange, NavigateOptions, Navigator, OutputMatch, Params, RouteSectionProps, RouteLoadFunc, RouteLoadFuncArgs, RouteDefinition, RouterIntegration, RouterUtils, SetParams, BeforeLeaveEventArgs } from "./types";
|
package/dist/index.js
CHANGED
|
@@ -239,13 +239,15 @@ function createRoutes(routeDef, base = "") {
|
|
|
239
239
|
const {
|
|
240
240
|
component,
|
|
241
241
|
load,
|
|
242
|
-
children
|
|
242
|
+
children,
|
|
243
|
+
metadata
|
|
243
244
|
} = routeDef;
|
|
244
245
|
const isLeaf = !children || Array.isArray(children) && !children.length;
|
|
245
246
|
const shared = {
|
|
246
247
|
key: routeDef,
|
|
247
248
|
component,
|
|
248
|
-
load
|
|
249
|
+
load,
|
|
250
|
+
metadata
|
|
249
251
|
};
|
|
250
252
|
return asArray(routeDef.path).reduce((acc, path) => {
|
|
251
253
|
for (const originalPath of expandOptionals(path)) {
|
|
@@ -612,6 +614,20 @@ const createRouterComponent = router => props => {
|
|
|
612
614
|
};
|
|
613
615
|
function Routes(props) {
|
|
614
616
|
const matches = createMemo(() => getRouteMatches(props.branches, props.routerState.location.pathname));
|
|
617
|
+
if (isServer) {
|
|
618
|
+
const e = getRequestEvent();
|
|
619
|
+
e && (e.routerMatches || (e.routerMatches = [])).push(matches().map(({
|
|
620
|
+
route,
|
|
621
|
+
path,
|
|
622
|
+
params
|
|
623
|
+
}) => ({
|
|
624
|
+
path: route.originalPath,
|
|
625
|
+
pattern: route.pattern,
|
|
626
|
+
match: path,
|
|
627
|
+
params,
|
|
628
|
+
metadata: route.metadata
|
|
629
|
+
})));
|
|
630
|
+
}
|
|
615
631
|
const params = createMemoObject(() => {
|
|
616
632
|
const m = matches();
|
|
617
633
|
const params = {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/*@refresh skip*/
|
|
2
|
+
import { getRequestEvent, isServer } from "solid-js/web";
|
|
2
3
|
import { children, createMemo, createRoot, mergeProps, on, Show } from "solid-js";
|
|
3
4
|
import { createBranches, createRouteContext, createRouterContext, getRouteMatches, RouteContextObj, RouterContextObj } from "../routing";
|
|
4
5
|
import { createMemoObject } from "../utils";
|
|
@@ -14,6 +15,17 @@ export const createRouterComponent = (router) => (props) => {
|
|
|
14
15
|
};
|
|
15
16
|
function Routes(props) {
|
|
16
17
|
const matches = createMemo(() => getRouteMatches(props.branches, props.routerState.location.pathname));
|
|
18
|
+
if (isServer) {
|
|
19
|
+
const e = getRequestEvent();
|
|
20
|
+
e &&
|
|
21
|
+
(e.routerMatches || (e.routerMatches = [])).push(matches().map(({ route, path, params }) => ({
|
|
22
|
+
path: route.originalPath,
|
|
23
|
+
pattern: route.pattern,
|
|
24
|
+
match: path,
|
|
25
|
+
params,
|
|
26
|
+
metadata: route.metadata
|
|
27
|
+
})));
|
|
28
|
+
}
|
|
17
29
|
const params = createMemoObject(() => {
|
|
18
30
|
const m = matches();
|
|
19
31
|
const params = {};
|
package/dist/routing.js
CHANGED
|
@@ -56,12 +56,13 @@ export const useBeforeLeave = (listener) => {
|
|
|
56
56
|
onCleanup(s);
|
|
57
57
|
};
|
|
58
58
|
export function createRoutes(routeDef, base = "") {
|
|
59
|
-
const { component, load, children } = routeDef;
|
|
59
|
+
const { component, load, children, metadata } = routeDef;
|
|
60
60
|
const isLeaf = !children || (Array.isArray(children) && !children.length);
|
|
61
61
|
const shared = {
|
|
62
62
|
key: routeDef,
|
|
63
63
|
component,
|
|
64
|
-
load
|
|
64
|
+
load,
|
|
65
|
+
metadata
|
|
65
66
|
};
|
|
66
67
|
return asArray(routeDef.path).reduce((acc, path) => {
|
|
67
68
|
for (const originalPath of expandOptionals(path)) {
|
package/dist/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Component, JSX, Signal } from "solid-js";
|
|
|
2
2
|
declare module "solid-js/web" {
|
|
3
3
|
interface RequestEvent {
|
|
4
4
|
response?: Response;
|
|
5
|
+
routerMatches?: OutputMatch[][];
|
|
5
6
|
routerCache?: Map<any, any>;
|
|
6
7
|
initialSubmission?: Submission<any, any>;
|
|
7
8
|
serverOnly?: boolean;
|
|
@@ -60,6 +61,7 @@ export type RouteDefinition<S extends string | string[] = any, T = unknown> = {
|
|
|
60
61
|
load?: RouteLoadFunc<T>;
|
|
61
62
|
children?: RouteDefinition | RouteDefinition[];
|
|
62
63
|
component?: Component<RouteSectionProps<T>>;
|
|
64
|
+
metadata?: Record<string, any>;
|
|
63
65
|
};
|
|
64
66
|
export type MatchFilter = readonly string[] | RegExp | ((s: string) => boolean);
|
|
65
67
|
export type PathParams<P extends string | readonly string[]> = P extends `${infer Head}/${infer Tail}` ? [...PathParams<Head>, ...PathParams<Tail>] : P extends `:${infer S}?` ? [S] : P extends `:${infer S}` ? [S] : P extends `*${infer S}` ? [S] : [];
|
|
@@ -74,10 +76,11 @@ export interface RouteMatch extends PathMatch {
|
|
|
74
76
|
route: Route;
|
|
75
77
|
}
|
|
76
78
|
export interface OutputMatch {
|
|
77
|
-
originalPath: string;
|
|
78
|
-
pattern: string;
|
|
79
79
|
path: string;
|
|
80
|
+
pattern: string;
|
|
81
|
+
match: string;
|
|
80
82
|
params: Params;
|
|
83
|
+
metadata?: Record<string, any>;
|
|
81
84
|
}
|
|
82
85
|
export interface Route {
|
|
83
86
|
key: unknown;
|
|
@@ -87,6 +90,7 @@ export interface Route {
|
|
|
87
90
|
load?: RouteLoadFunc;
|
|
88
91
|
matcher: (location: string) => PathMatch | null;
|
|
89
92
|
matchFilters?: MatchFilters;
|
|
93
|
+
metadata?: Record<string, any>;
|
|
90
94
|
}
|
|
91
95
|
export interface Branch {
|
|
92
96
|
routes: Route[];
|
|
@@ -108,16 +112,6 @@ export interface RouterUtils {
|
|
|
108
112
|
go(delta: number): void;
|
|
109
113
|
beforeLeave: BeforeLeaveLifecycle;
|
|
110
114
|
}
|
|
111
|
-
export interface OutputMatch {
|
|
112
|
-
originalPath: string;
|
|
113
|
-
pattern: string;
|
|
114
|
-
path: string;
|
|
115
|
-
params: Params;
|
|
116
|
-
}
|
|
117
|
-
export interface RouterOutput {
|
|
118
|
-
url?: string;
|
|
119
|
-
matches: OutputMatch[][];
|
|
120
|
-
}
|
|
121
115
|
export interface RouterContext {
|
|
122
116
|
base: RouteContext;
|
|
123
117
|
location: Location;
|