@openwebf/react-router 0.22.18 → 0.24.0

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 CHANGED
@@ -2,6 +2,8 @@ import React, { SyntheticEvent, EventHandler, ReactNode, FC } from 'react';
2
2
  import { WebFElementWithMethods } from '@openwebf/react-core-ui';
3
3
 
4
4
  type RoutePath = string;
5
+ type EnsureRouteMountedCallback = (pathname: string) => Promise<void> | void;
6
+ declare function __unstable_setEnsureRouteMountedCallback(callback: EnsureRouteMountedCallback | null): void;
5
7
  /**
6
8
  * Single entry in the hybrid router stack.
7
9
  * Mirrors the data returned from webf.hybridHistory.buildContextStack.
@@ -27,7 +29,7 @@ declare const WebFRouter: {
27
29
  /**
28
30
  * Get the current route path
29
31
  */
30
- readonly path: RoutePath;
32
+ readonly path: string;
31
33
  /**
32
34
  * Navigate to a specified route
33
35
  * Applies route guards for permission checks before navigation
@@ -91,6 +93,43 @@ declare const WebFRouter: {
91
93
  */
92
94
  restorablePopAndPushNamed: <T extends RoutePath>(path: T, state?: any) => Promise<string>;
93
95
  };
96
+ /**
97
+ * Route parameters extracted from dynamic routes
98
+ */
99
+ interface RouteParams {
100
+ [key: string]: string;
101
+ }
102
+ /**
103
+ * Route match result
104
+ */
105
+ interface RouteMatch {
106
+ path: string;
107
+ params: RouteParams;
108
+ isExact: boolean;
109
+ }
110
+ /**
111
+ * Convert a route pattern to a regular expression
112
+ * @param pattern Route pattern like "/user/:userId" or "/category/:catId/product/:prodId"
113
+ * @returns Object with regex and parameter names
114
+ */
115
+ declare function pathToRegex(pattern: string): {
116
+ regex: RegExp;
117
+ paramNames: string[];
118
+ };
119
+ /**
120
+ * Match a pathname against a route pattern and extract parameters
121
+ * @param pattern Route pattern like "/user/:userId"
122
+ * @param pathname Actual pathname like "/user/123"
123
+ * @returns Match result with extracted parameters or null if no match
124
+ */
125
+ declare function matchPath(pattern: string, pathname: string): RouteMatch | null;
126
+ /**
127
+ * Find the best matching route from a list of route patterns
128
+ * @param routes Array of route patterns
129
+ * @param pathname Current pathname
130
+ * @returns Best match or null if no routes match
131
+ */
132
+ declare function matchRoutes(routes: string[], pathname: string): RouteMatch | null;
94
133
 
95
134
  /**
96
135
  * Route Component
@@ -116,6 +155,11 @@ interface RouteProps {
116
155
  * Must be a member of the RoutePath enum
117
156
  */
118
157
  path: string;
158
+ /**
159
+ * The concrete path to mount for this route instance.
160
+ * Used internally to support dynamic routes like `/users/:id` mounting at `/users/123`.
161
+ */
162
+ mountedPath?: string;
119
163
  /**
120
164
  * Whether to pre-render
121
165
  * If true, the page will be rendered when the app starts, rather than waiting for route navigation
@@ -129,13 +173,20 @@ interface RouteProps {
129
173
  * The actual page component to render
130
174
  */
131
175
  element: React.ReactNode;
176
+ /**
177
+ * Theme for this route
178
+ * Controls the visual style of the navigation bar and page
179
+ *
180
+ * @default "material"
181
+ */
182
+ theme?: 'material' | 'cupertino';
132
183
  }
133
184
  /**
134
185
  * Route Component
135
186
  *
136
187
  * Responsible for managing page rendering, lifecycle and navigation bar
137
188
  */
138
- declare function Route({ path, prerender, element, title }: RouteProps): React.JSX.Element;
189
+ declare function Route({ path, mountedPath, prerender, element, title, theme }: RouteProps): React.JSX.Element;
139
190
 
140
191
  /**
141
192
  * Hook to get route context
@@ -157,11 +208,19 @@ declare function useRouteContext(): {
157
208
  * Current route path, corresponds to RoutePath enum
158
209
  */
159
210
  path: string | undefined;
211
+ /**
212
+ * The concrete mounted path for this route instance (e.g. `/users/123`).
213
+ */
214
+ mountedPath: string | undefined;
160
215
  /**
161
216
  * Page state
162
217
  * State data passed during route navigation
163
218
  */
164
219
  params: any;
220
+ /**
221
+ * Route parameters extracted from dynamic routes (e.g., :userId in /user/:userId)
222
+ */
223
+ routeParams: RouteParams | undefined;
165
224
  /**
166
225
  * Current active path from router
167
226
  */
@@ -199,6 +258,7 @@ interface Location {
199
258
  * const location = useLocation();
200
259
  *
201
260
  * console.log('Current path:', location.pathname);
261
+
202
262
  * console.log('Location state:', location.state);
203
263
  * console.log('Is active:', location.isActive);
204
264
  *
@@ -209,6 +269,24 @@ interface Location {
209
269
  declare function useLocation(): Location & {
210
270
  isActive: boolean;
211
271
  };
272
+ /**
273
+ * Hook to get route parameters from dynamic routes
274
+ *
275
+ * @returns Route parameters object with parameter names as keys and values as strings
276
+ *
277
+ * @example
278
+ * ```tsx
279
+ * // For route pattern "/user/:userId" and actual path "/user/123"
280
+ * function UserPage() {
281
+ * const params = useParams();
282
+ *
283
+ * console.log(params.userId); // "123"
284
+ *
285
+ * return <div>User ID: {params.userId}</div>;
286
+ * }
287
+ * ```
288
+ */
289
+ declare function useParams(): RouteParams;
212
290
  /**
213
291
  * Route configuration object
214
292
  */
@@ -225,6 +303,12 @@ interface RouteObject {
225
303
  * Whether to pre-render this route
226
304
  */
227
305
  prerender?: boolean;
306
+ /**
307
+ * Theme for this route
308
+ *
309
+ * @default "material"
310
+ */
311
+ theme?: 'material' | 'cupertino';
228
312
  /**
229
313
  * Child routes (not supported yet)
230
314
  */
@@ -350,6 +434,7 @@ type HybridRouterChangeEventHandler = EventHandler<HybridRouterChangeEvent>;
350
434
  interface WebFHybridRouterProps {
351
435
  path: string;
352
436
  title?: string;
437
+ theme?: 'material' | 'cupertino';
353
438
  onScreen?: HybridRouterChangeEventHandler;
354
439
  offScreen?: HybridRouterChangeEventHandler;
355
440
  children?: ReactNode;
@@ -358,5 +443,5 @@ interface WebFRouterLinkElement extends WebFElementWithMethods<{}> {
358
443
  }
359
444
  declare const WebFRouterLink: FC<WebFHybridRouterProps>;
360
445
 
361
- export { Route, Routes, WebFRouter, WebFRouterLink, useLocation, useNavigate, useRouteContext, useRoutes };
362
- export type { HybridRouteStackEntry, HybridRouterChangeEvent, HybridRouterChangeEventHandler, Location, NavigateFunction, NavigateOptions, NavigationMethods, RouteObject, RouteProps, RoutesProps, WebFHybridRouterProps, WebFRouterLinkElement };
446
+ export { Route, Routes, WebFRouter, WebFRouterLink, __unstable_setEnsureRouteMountedCallback, matchPath, matchRoutes, pathToRegex, useLocation, useNavigate, useParams, useRouteContext, useRoutes };
447
+ export type { HybridRouteStackEntry, HybridRouterChangeEvent, HybridRouterChangeEventHandler, Location, NavigateFunction, NavigateOptions, NavigationMethods, RouteMatch, RouteObject, RouteParams, RouteProps, RoutesProps, WebFHybridRouterProps, WebFRouterLinkElement };