mobx-route 1.3.3 → 2.0.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <img src="docs/public/logo.png" align="right" width="156" alt="logo" />
2
2
 
3
- # mobx-route
3
+ # mobx-route
4
4
 
5
5
  [![NPM version][npm-image]][npm-url] [![build status][github-build-actions-image]][github-actions-url] [![npm download][download-image]][download-url] [![bundle size][bundlephobia-image]][bundlephobia-url]
6
6
 
@@ -14,23 +14,189 @@
14
14
  [bundlephobia-url]: https://bundlephobia.com/result?p=mobx-route
15
15
  [bundlephobia-image]: https://badgen.net/bundlephobia/minzip/mobx-route
16
16
 
17
+ 🚀 Simple and lightweight **typed** MobX router 🚀
18
+ _Uses [`path-to-regexp`](https://www.npmjs.com/package/path-to-regexp) power for path matching_
17
19
 
18
- 🚀 Simple and lightweight typed MobX router 🚀
19
- _Uses [`path-to-regexp` power](https://www.npmjs.com/package/path-to-regexp)_
20
+ ### [📖 Read the docs →](https://js2me.github.io/mobx-route/)
20
21
 
21
- ### [Read the docs →](https://js2me.github.io/mobx-route/)
22
+ ---
22
23
 
24
+ ## Quick Start
23
25
 
24
26
  ```ts
25
27
  import { createRoute } from "mobx-route";
26
28
 
27
29
  const userDetails = createRoute("/users/:id");
28
30
 
29
- await userDetails.open({ id: 1 }); // path params are required
31
+ // Path params are required TypeScript enforces it
32
+ await userDetails.open({ id: 1 });
30
33
 
31
- userDetails.isOpened; // true;
34
+ userDetails.isOpened; // true
35
+ userDetails.params; // { id: "1" } — fully typed
32
36
  ```
33
37
 
34
- ## Contribution Guide
38
+ ---
35
39
 
36
- Want to contribute ? [Follow this guide](https://github.com/js2me/mobx-route/blob/master/CONTRIBUTING.md)
40
+ ## Features
41
+
42
+ ### 🔗 Nested Routes with `.extend()`
43
+
44
+ Build route trees naturally — no config arrays, no `<Routes>` wrappers:
45
+
46
+ ```ts
47
+ const users = createRoute("/users");
48
+ const userDetails = users.extend("/:userId");
49
+ const userPhotos = userDetails.extend("/photos");
50
+
51
+ // Path is auto-concatenated: /users/:userId/photos
52
+ await userPhotos.open({ userId: 42 });
53
+ // → /users/42/photos
54
+
55
+ users.isOpened; // true (parent is open too)
56
+ users.hasOpenedChildren; // true
57
+ ```
58
+
59
+ ### 🛡️ Route Guards & Redirects
60
+
61
+ Protect routes with `beforeOpen` — cancel navigation or redirect:
62
+
63
+ ```ts
64
+ const dashboard = createRoute("/dashboard", {
65
+ beforeOpen: async () => {
66
+ if (!await isAuthenticated()) {
67
+ return { url: "/login", replace: true }; // redirect
68
+ }
69
+ // return undefined → proceed
70
+ },
71
+ checkOpened: () => currentUser.isAuthorized, // reactive predicate
72
+ });
73
+ ```
74
+
75
+ ### 🔮 Virtual Routes for Modals & Drawers
76
+
77
+ Same `.open()` / `.close()` / `.isOpened` API — but no URL involved:
78
+
79
+ ```ts
80
+ const authModal = createVirtualRoute({
81
+ checkOpened: (route) => route.query.data.modal === "auth",
82
+ open: (_, route) => route.query.update({ modal: "auth" }),
83
+ close: (route) => route.query.update({ modal: undefined }),
84
+ beforeClose: () => !hasUnsavedChanges, // prevent closing
85
+ });
86
+
87
+ authModal.isOpened; // reactive — auto-updates from query
88
+ authModal.isClosing; // for exit animations
89
+ ```
90
+
91
+ ### 🎯 Typed Query Params
92
+
93
+ ```ts
94
+ const search = createRoute<
95
+ "/search",
96
+ {},
97
+ {},
98
+ { q: string; page?: number; sort?: "asc" | "desc" }
99
+ >("/search");
100
+
101
+ // TQueryParams types the INPUT — what you pass to open()
102
+ await search.open({}, { query: { q: "mobx", page: 1 } });
103
+
104
+ // query.data is always Record<string, string> at runtime (values come from URL)
105
+ search.query.data.q; // string
106
+ search.query.data.page; // string | undefined — use Number() or QueryParam for typed access
107
+ ```
108
+
109
+ ### 🔄 `update()` for In-Place Changes
110
+
111
+ Replace params without polluting browser history:
112
+
113
+ ```ts
114
+ await userRoute.open({ userId: 1 }, { query: { tab: "profile" } });
115
+ await userRoute.update({ userId: 2 });
116
+ // → /users/2?tab=profile (replace: true, mergeQuery: true by default)
117
+ ```
118
+
119
+ ### 🧩 React Integration
120
+
121
+ ```tsx
122
+ import { RouteView, RouteViewGroup, Link } from "mobx-route/react";
123
+
124
+ // Declarative route rendering
125
+ <RouteView route={userRoute} view={UserPage} fallback={<Loading />} />
126
+
127
+ // Route switching with fallback
128
+ <RouteViewGroup otherwise={notFoundRoute}>
129
+ <RouteView route={homeRoute} view={HomePage} />
130
+ <RouteView route={userRoute} view={UserPage} />
131
+ <div>Not found</div>
132
+ </RouteViewGroup>
133
+
134
+ // Type-safe links
135
+ <Link to={userRoute} params={{ userId: 42 }}>Profile</Link>
136
+ ```
137
+
138
+ ### 🧠 View Model Integration
139
+
140
+ ```ts
141
+ import { RouteViewModel } from "mobx-route/view-model";
142
+
143
+ class UserPageVM extends RouteViewModel<typeof userRoute> {
144
+ route = userRoute;
145
+ // payload, pathParams, query, isMounted — all built-in
146
+ }
147
+ ```
148
+
149
+ ### 🌍 Optional Path Segments & Wildcards
150
+
151
+ ```ts
152
+ // Optional segment
153
+ const route = createRoute("/users{/:tab}");
154
+ route.open(); // → /users
155
+ route.open({ tab: 1 }); // → /users/1
156
+
157
+ // Wildcard/rest params
158
+ const docs = createRoute("/docs/*rest");
159
+ docs.open({ rest: ["api", "v2", "auth"] }); // → /docs/api/v2/auth
160
+ ```
161
+
162
+ ### 📦 Tree-Shakeable Subpath Exports
163
+
164
+ Only pay for what you use:
165
+
166
+ ```ts
167
+ import { createRoute } from "mobx-route"; // core only
168
+ import { RouteView, Link } from "mobx-route/react"; // + React
169
+ import { RouteViewModel } from "mobx-route/view-model"; // + VM
170
+ ```
171
+
172
+ ---
173
+
174
+ ## Installation
175
+
176
+ ```bash
177
+ npm install mobx-route
178
+ # or
179
+ pnpm add mobx-route
180
+ # or
181
+ yarn add mobx-route
182
+ ```
183
+
184
+ Peer dependencies (React integration is optional):
185
+
186
+ ```bash
187
+ npm install mobx
188
+ # For React:
189
+ npm install mobx-react-lite react react-dom
190
+ ```
191
+
192
+ ---
193
+
194
+ ## Contribution Guide
195
+
196
+ Want to contribute? [Follow this guide](https://github.com/js2me/mobx-route/blob/master/CONTRIBUTING.md)
197
+
198
+ ---
199
+
200
+ ## License
201
+
202
+ [MIT](https://github.com/js2me/mobx-route/blob/master/LICENSE)
package/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const mobxLocationHistory = require("mobx-location-history");
4
- const virtualRoute = require("./virtual-route-sU8rVTsu.cjs");
4
+ const virtualRoute = require("./virtual-route-DCnOqDz5.cjs");
5
5
  const isRouteEntity = (route) => route && "isOpened" in route;
6
6
  exports.Route = virtualRoute.Route;
7
7
  exports.RouteGroup = virtualRoute.RouteGroup;
package/index.d.ts CHANGED
@@ -4,17 +4,20 @@ import * as yummies_complex from 'yummies/complex';
4
4
  import { ParseOptions, MatchOptions, ParamData, TokenData } from 'path-to-regexp';
5
5
  import { AnyObject, EmptyObject, IsPartial, Maybe, MaybeFn, MaybePromise } from 'yummies/types';
6
6
 
7
- type AnyVirtualRoute = VirtualRoute<any> | AbstractVirtualRoute<any>;
8
- interface VirtualOpenExtraParams extends Omit<RouteNavigateParams, 'state' | 'mergeQuery'> {
7
+ type AnyVirtualRoute = VirtualRoute<any, any> | AbstractVirtualRoute<any, any>;
8
+ interface VirtualOpenExtraParams<TQueryParams extends Record<string, any> = AnyObject> extends Omit<RouteNavigateParams<TQueryParams>, 'state' | 'mergeQuery'> {
9
9
  }
10
- interface AbstractVirtualRoute<TParams extends AnyObject | EmptyObject = EmptyObject> {
10
+ interface AbstractVirtualRoute<TParams extends AnyObject | EmptyObject = EmptyObject, TQueryParams extends Record<string, any> = AnyObject> {
11
11
  isOpened: boolean;
12
12
  isOpening: boolean;
13
13
  params: TParams | null;
14
14
  /**
15
15
  * [**Documentation**](https://js2me.github.io/mobx-route/core/VirtualRoute.html#open)
16
16
  */
17
- open(...args: IsPartial<TParams> extends true ? [params?: Maybe<TParams>, extraParams?: VirtualOpenExtraParams] : [params: TParams, extraParams?: VirtualOpenExtraParams]): Promise<void>;
17
+ open(...args: IsPartial<TParams> extends true ? [
18
+ params?: Maybe<TParams>,
19
+ extraParams?: VirtualOpenExtraParams<TQueryParams>
20
+ ] : [params: TParams, extraParams?: VirtualOpenExtraParams<TQueryParams>]): Promise<void>;
18
21
  }
19
22
  interface VirtualRouteConfiguration<TParams extends AnyObject | EmptyObject = EmptyObject> {
20
23
  /**
@@ -73,9 +76,9 @@ interface VirtualRouteConfiguration<TParams extends AnyObject | EmptyObject = Em
73
76
  */
74
77
  afterUpdate?: (params: NoInfer<TParams | null>, route: VirtualRoute<NoInfer<TParams>>) => void;
75
78
  }
76
- interface VirtualRouteTrx {
79
+ interface VirtualRouteTrx<TQueryParams extends Record<string, any> = AnyObject> {
77
80
  params: any;
78
- extra?: Maybe<VirtualOpenExtraParams>;
81
+ extra?: Maybe<VirtualOpenExtraParams<TQueryParams>>;
79
82
  manual?: boolean;
80
83
  }
81
84
 
@@ -84,7 +87,7 @@ interface VirtualRouteTrx {
84
87
  *
85
88
  * [**Documentation**](https://js2me.github.io/mobx-route/core/VirtualRoute.html)
86
89
  */
87
- declare class VirtualRoute<TParams extends AnyObject | EmptyObject = EmptyObject> implements AbstractVirtualRoute<TParams> {
90
+ declare class VirtualRoute<TParams extends AnyObject | EmptyObject = EmptyObject, TQueryParams extends Record<string, any> = AnyObject> implements AbstractVirtualRoute<TParams, TQueryParams> {
88
91
  protected config: VirtualRouteConfiguration<TParams>;
89
92
  private isDestroyed?;
90
93
  private disposer?;
@@ -120,7 +123,10 @@ declare class VirtualRoute<TParams extends AnyObject | EmptyObject = EmptyObject
120
123
  /**
121
124
  * [**Documentation**](https://js2me.github.io/mobx-route/core/VirtualRoute.html#open)
122
125
  */
123
- open(...args: IsPartial<TParams> extends true ? [params?: Maybe<TParams>, extraParams?: VirtualOpenExtraParams] : [params: TParams, extraParams?: VirtualOpenExtraParams]): Promise<void>;
126
+ open(...args: IsPartial<TParams> extends true ? [
127
+ params?: Maybe<TParams>,
128
+ extraParams?: VirtualOpenExtraParams<TQueryParams>
129
+ ] : [params: TParams, extraParams?: VirtualOpenExtraParams<TQueryParams>]): Promise<void>;
124
130
  /**
125
131
  * [**Documentation**](https://js2me.github.io/mobx-route/core/VirtualRoute.html#close)
126
132
  */
@@ -129,7 +135,7 @@ declare class VirtualRoute<TParams extends AnyObject | EmptyObject = EmptyObject
129
135
  private confirmClosing;
130
136
  destroy(): void;
131
137
  }
132
- declare const createVirtualRoute: <TParams extends AnyObject | EmptyObject = EmptyObject>(config?: VirtualRouteConfiguration<TParams>) => VirtualRoute<TParams>;
138
+ declare const createVirtualRoute: <TParams extends AnyObject | EmptyObject = EmptyObject, TQueryParams extends Record<string, any> = AnyObject>(config?: VirtualRouteConfiguration<TParams>) => VirtualRoute<TParams, TQueryParams>;
133
139
 
134
140
  /**
135
141
  * Class for grouping related routes and managing their state.
@@ -185,7 +191,7 @@ type RoutesArrayCollection = AnyAbstractRouteEntity[];
185
191
  type RoutesObjectCollection = Record<string, AnyAbstractRouteEntity>;
186
192
  type RoutesCollection = RoutesArrayCollection | RoutesObjectCollection;
187
193
 
188
- type NavigationTrx<TParams extends AnyObject = AnyObject> = {
194
+ type NavigationTrx<TParams extends AnyObject = AnyObject, TQueryParams extends Record<string, any> = AnyObject> = {
189
195
  state?: any;
190
196
  /**
191
197
  * path parameters
@@ -195,19 +201,19 @@ type NavigationTrx<TParams extends AnyObject = AnyObject> = {
195
201
  params?: TParams;
196
202
  url: string;
197
203
  replace?: boolean;
198
- query?: AnyObject;
204
+ query?: Partial<TQueryParams>;
199
205
  preferSkipHistoryUpdate?: boolean;
200
206
  };
201
207
  /**
202
208
  * Returning `false` means ignore navigation
203
209
  */
204
210
  type BeforeOpenFeedback = void | boolean | Pick<NavigationTrx, 'url' | 'state' | 'replace'>;
205
- interface UrlCreateParams<TInputParams> {
211
+ interface UrlCreateParams<TInputParams, TQueryParams extends Record<string, any> = AnyObject> {
206
212
  baseUrl?: string | undefined;
207
213
  params: TInputParams;
208
- query: AnyObject;
214
+ query: Partial<TQueryParams>;
209
215
  }
210
- type UrlCreateParamsFn<TInputParams = any> = (params: UrlCreateParams<TInputParams>, currentQueryData: RawQueryParamsData) => Maybe<UrlCreateParams<TInputParams>>;
216
+ type UrlCreateParamsFn<TInputParams = any, TQueryParams extends Record<string, any> = AnyObject> = (params: UrlCreateParams<TInputParams, TQueryParams>, currentQueryData: RawQueryParamsData) => Maybe<UrlCreateParams<TInputParams, TQueryParams>>;
211
217
  /**
212
218
  * Output options for `createUrl()` (third argument).
213
219
  * @see [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#createurl)
@@ -218,7 +224,7 @@ interface CreatedUrlOutputParams {
218
224
  /** @see [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#createurl) */
219
225
  omitQuery?: boolean;
220
226
  }
221
- interface RouteConfiguration<TPath extends string, TInputParams extends InputPathParams<TPath> = InputPathParams<TPath>, TOutputParams extends AnyObject = ParsedPathParams<TPath>, TParentRoute extends Route<string, any, any, any> | null = null> extends Omit<Partial<RouteGlobalConfig>, 'createUrl'> {
227
+ interface RouteConfiguration<TPath extends string, TInputParams extends InputPathParams<TPath> = InputPathParams<TPath>, TOutputParams extends AnyObject = ParsedPathParams<TPath>, TQueryParams extends Record<string, any> = AnyObject> extends Omit<Partial<RouteGlobalConfig>, 'createUrl'> {
222
228
  /**
223
229
  * [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#abortsignal)
224
230
  */
@@ -236,7 +242,7 @@ interface RouteConfiguration<TPath extends string, TInputParams extends InputPat
236
242
  meta?: AnyObject;
237
243
  parseOptions?: ParseOptions;
238
244
  matchOptions?: MatchOptions & ParseOptions;
239
- parent?: TParentRoute;
245
+ parent?: AnyRoute | null;
240
246
  children?: AnyRoute[];
241
247
  /**
242
248
  * [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#params)
@@ -249,7 +255,7 @@ interface RouteConfiguration<TPath extends string, TInputParams extends InputPat
249
255
  /**
250
256
  * [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#beforeopen)
251
257
  */
252
- beforeOpen?: (navigationTransaction: NavigationTrx<NoInfer<TInputParams>>) => MaybePromise<BeforeOpenFeedback>;
258
+ beforeOpen?: (navigationTransaction: NavigationTrx<NoInfer<TInputParams>, NoInfer<TQueryParams>>) => MaybePromise<BeforeOpenFeedback>;
253
259
  /**
254
260
  * [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#afterclose)
255
261
  */
@@ -257,15 +263,15 @@ interface RouteConfiguration<TPath extends string, TInputParams extends InputPat
257
263
  /**
258
264
  * [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#afteropen)
259
265
  */
260
- afterOpen?: (data: ParsedPathData<NoInfer<TPath>>, route: Route<NoInfer<TPath>, NoInfer<TInputParams>, NoInfer<TOutputParams>, NoInfer<TParentRoute>>) => void;
266
+ afterOpen?: (data: ParsedPathData<NoInfer<TPath>>, route: Route<NoInfer<TPath>, NoInfer<TInputParams>, NoInfer<TOutputParams>, NoInfer<TQueryParams>>) => void;
261
267
  /**
262
268
  * [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#afterupdate)
263
269
  */
264
- afterUpdate?: (data: ParsedPathData<NoInfer<TPath>>, route: Route<NoInfer<TPath>, NoInfer<TInputParams>, NoInfer<TOutputParams>, NoInfer<TParentRoute>>) => void;
270
+ afterUpdate?: (data: ParsedPathData<NoInfer<TPath>>, route: Route<NoInfer<TPath>, NoInfer<TInputParams>, NoInfer<TOutputParams>, NoInfer<TQueryParams>>) => void;
265
271
  /**
266
272
  * [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#createurl)
267
273
  */
268
- createUrl?: UrlCreateParamsFn<TInputParams>;
274
+ createUrl?: UrlCreateParamsFn<TInputParams, TQueryParams>;
269
275
  }
270
276
  type AnyRoute = Route<any, any, any, any>;
271
277
  type InputPathParam = string | number | boolean | null;
@@ -287,10 +293,10 @@ type PathToObject<Path extends string, PropertyValue = string> = Simplify<Path e
287
293
  } : {}>;
288
294
  type ParsedPathParams<Path extends string> = PathToObject<Path, ParsedPathParam>;
289
295
  type InputPathParams<Path extends string> = PathToObject<Path, InputPathParam>;
290
- interface RouteNavigateParams {
296
+ interface RouteNavigateParams<TQueryParams extends Record<string, any> = AnyObject> {
291
297
  replace?: boolean;
292
298
  state?: any;
293
- query?: AnyObject;
299
+ query?: Partial<TQueryParams>;
294
300
  mergeQuery?: boolean;
295
301
  }
296
302
  interface ParsedPathData<TPath extends string> {
@@ -300,14 +306,21 @@ interface ParsedPathData<TPath extends string> {
300
306
  type InferPath<T extends AnyRoute> = T extends Route<infer TPath, any, any, any> ? TPath : never;
301
307
  type InferInputParams<T extends AnyRoute> = T extends VirtualRoute<infer TParams> ? TParams : T extends Route<any, infer TInputParams, any, any> ? TInputParams : never;
302
308
  type InferParams<T extends AnyRoute> = T extends VirtualRoute<infer TParams> ? TParams : T extends Route<any, any, infer TParams, any> ? TParams : never;
309
+ /**
310
+ * Extracts the query params input type from a route.
311
+ *
312
+ * Note: this represents the INPUT shape used in `open()`, `createUrl()`, etc.
313
+ * The actual `route.query.data` values are always `Record<string, string>` at runtime.
314
+ */
315
+ type InferQueryParams<T extends AnyRoute> = T extends Route<any, any, any, infer TQueryParams> ? TQueryParams : never;
303
316
 
304
317
  /**
305
318
  * Class for creating path based route.
306
319
  *
307
320
  * [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html)
308
321
  */
309
- declare class Route<TPath extends string, TInputParams extends InputPathParams<TPath> = InputPathParams<TPath>, TOutputParams extends AnyObject = ParsedPathParams<TPath>, TParentRoute extends Route<any, any, any, any> | null = null> {
310
- protected config: RouteConfiguration<TPath, TInputParams, TOutputParams, TParentRoute>;
322
+ declare class Route<TPath extends string, TInputParams extends InputPathParams<TPath> = InputPathParams<TPath>, TOutputParams extends AnyObject = ParsedPathParams<TPath>, TQueryParams extends Record<string, any> = AnyObject> {
323
+ protected config: RouteConfiguration<TPath, TInputParams, TOutputParams, TQueryParams>;
311
324
  private isDestroyed?;
312
325
  private disposer?;
313
326
  protected history: History;
@@ -316,7 +329,7 @@ declare class Route<TPath extends string, TInputParams extends InputPathParams<T
316
329
  *
317
330
  * [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#parent)
318
331
  */
319
- parent: TParentRoute;
332
+ parent: AnyRoute | null;
320
333
  query: IQueryParams;
321
334
  private _tokenData;
322
335
  private _matcher?;
@@ -350,7 +363,7 @@ declare class Route<TPath extends string, TInputParams extends InputPathParams<T
350
363
  * [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#children)
351
364
  */
352
365
  children: AnyRoute[];
353
- constructor(pathDeclaration: TPath, config?: RouteConfiguration<TPath, TInputParams, TOutputParams, TParentRoute>);
366
+ constructor(pathDeclaration: TPath, config?: RouteConfiguration<TPath, TInputParams, TOutputParams, TQueryParams>);
354
367
  protected get baseUrl(): string | undefined;
355
368
  /**
356
369
  * Checks whether current route matches provided path.
@@ -397,7 +410,7 @@ declare class Route<TPath extends string, TInputParams extends InputPathParams<T
397
410
  *
398
411
  * [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#extend)
399
412
  */
400
- extend<TExtendedPath extends string, TExtendedInputParams extends InputPathParams<`${TPath}${TExtendedPath}`> = InputPathParams<`${TPath}${TExtendedPath}`>, TExtendedOutputParams extends AnyObject = TInputParams & ParsedPathParams<`${TPath}${TExtendedPath}`>>(pathDeclaration: TExtendedPath, config?: Omit<RouteConfiguration<`${TPath}${TExtendedPath}`, TInputParams & TExtendedInputParams, TExtendedOutputParams, any>, 'parent'>): Route<`${TPath}${TExtendedPath}`, TInputParams & TExtendedInputParams, TExtendedOutputParams, this>;
413
+ extend<TExtendedPath extends string, TExtendedInputParams extends InputPathParams<`${TPath}${TExtendedPath}`> = InputPathParams<`${TPath}${TExtendedPath}`>, TExtendedOutputParams extends AnyObject = TInputParams & ParsedPathParams<`${TPath}${TExtendedPath}`>, TExtendedQueryParams extends Record<string, any> = TQueryParams>(pathDeclaration: TExtendedPath, config?: Omit<RouteConfiguration<`${TPath}${TExtendedPath}`, TInputParams & TExtendedInputParams, TExtendedOutputParams, TExtendedQueryParams>, 'parent'>): Route<`${TPath}${TExtendedPath}`, TInputParams & TExtendedInputParams, TExtendedOutputParams, TExtendedQueryParams>;
401
414
  /**
402
415
  * Manually add child routes.
403
416
  *
@@ -422,11 +435,11 @@ declare class Route<TPath extends string, TInputParams extends InputPathParams<T
422
435
  */
423
436
  createUrl(...args: IsPartial<TInputParams> extends true ? [
424
437
  params?: Maybe<TInputParams>,
425
- query?: Maybe<AnyObject>,
438
+ query?: Maybe<Partial<TQueryParams>>,
426
439
  mergeQueryOrParams?: boolean | CreatedUrlOutputParams
427
440
  ] : [
428
441
  params: TInputParams,
429
- query?: Maybe<AnyObject>,
442
+ query?: Maybe<Partial<TQueryParams>>,
430
443
  mergeQueryOrParams?: boolean | CreatedUrlOutputParams
431
444
  ]): string;
432
445
  /**
@@ -436,19 +449,22 @@ declare class Route<TPath extends string, TInputParams extends InputPathParams<T
436
449
  */
437
450
  open(...args: IsPartial<TInputParams> extends true ? [
438
451
  params?: TInputParams | null | undefined,
439
- navigateParams?: RouteNavigateParams
440
- ] : [params: TInputParams, navigateParams?: RouteNavigateParams]): Promise<void>;
452
+ navigateParams?: RouteNavigateParams<TQueryParams>
453
+ ] : [
454
+ params: TInputParams,
455
+ navigateParams?: RouteNavigateParams<TQueryParams>
456
+ ]): Promise<void>;
441
457
  open(...args: IsPartial<TInputParams> extends true ? [
442
458
  params?: TInputParams | null | undefined,
443
- replace?: RouteNavigateParams['replace'],
444
- query?: RouteNavigateParams['query']
459
+ replace?: RouteNavigateParams<TQueryParams>['replace'],
460
+ query?: RouteNavigateParams<TQueryParams>['query']
445
461
  ] : [
446
462
  params: TInputParams,
447
- replace?: RouteNavigateParams['replace'],
448
- query?: RouteNavigateParams['query']
463
+ replace?: RouteNavigateParams<TQueryParams>['replace'],
464
+ query?: RouteNavigateParams<TQueryParams>['query']
449
465
  ]): Promise<void>;
450
- open(url: string, navigateParams?: RouteNavigateParams): Promise<void>;
451
- open(url: string, replace?: RouteNavigateParams['replace'], query?: RouteNavigateParams['query']): Promise<void>;
466
+ open(url: string, navigateParams?: RouteNavigateParams<TQueryParams>): Promise<void>;
467
+ open(url: string, replace?: RouteNavigateParams<TQueryParams>['replace'], query?: RouteNavigateParams<TQueryParams>['query']): Promise<void>;
452
468
  /**
453
469
  * Updates the current route if it is already open.
454
470
  * Unlike `open`, this is a no-op if the route is not open,
@@ -457,12 +473,12 @@ declare class Route<TPath extends string, TInputParams extends InputPathParams<T
457
473
  *
458
474
  * [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#update)
459
475
  */
460
- update(params?: TInputParams | null | undefined, navigateParams?: RouteNavigateParams): Promise<void>;
461
- update(params?: TInputParams | null | undefined, replace?: RouteNavigateParams['replace'], query?: RouteNavigateParams['query']): Promise<void>;
462
- update(url: string, navigateParams?: RouteNavigateParams): Promise<void>;
463
- update(url: string, replace?: RouteNavigateParams['replace'], query?: RouteNavigateParams['query']): Promise<void>;
476
+ update(params?: TInputParams | null | undefined, navigateParams?: RouteNavigateParams<TQueryParams>): Promise<void>;
477
+ update(params?: TInputParams | null | undefined, replace?: RouteNavigateParams<TQueryParams>['replace'], query?: RouteNavigateParams<TQueryParams>['query']): Promise<void>;
478
+ update(url: string, navigateParams?: RouteNavigateParams<TQueryParams>): Promise<void>;
479
+ update(url: string, replace?: RouteNavigateParams<TQueryParams>['replace'], query?: RouteNavigateParams<TQueryParams>['query']): Promise<void>;
464
480
  protected get tokenData(): TokenData;
465
- protected confirmOpening(trx: NavigationTrx<TInputParams>): Promise<true | undefined>;
481
+ protected confirmOpening(trx: NavigationTrx<TInputParams, TQueryParams>): Promise<true | undefined>;
466
482
  protected confirmClosing(): boolean;
467
483
  private firstPathMatchingRun;
468
484
  private checkPathMatch;
@@ -474,7 +490,7 @@ declare class Route<TPath extends string, TInputParams extends InputPathParams<T
474
490
  */
475
491
  destroy(): void;
476
492
  }
477
- declare const createRoute: <TPath extends string, TInputParams extends InputPathParams<TPath> = InputPathParams<TPath>, TOutputParams extends AnyObject = ParsedPathParams<TPath>, TParentRoute extends Route<any, any, any, any> | null = null>(path: TPath, config?: RouteConfiguration<TPath, TInputParams, TOutputParams, TParentRoute>) => Route<TPath, TInputParams, TOutputParams, TParentRoute>;
493
+ declare const createRoute: <TPath extends string, TInputParams extends InputPathParams<TPath> = InputPathParams<TPath>, TOutputParams extends AnyObject = ParsedPathParams<TPath>, TQueryParams extends Record<string, any> = AnyObject>(path: TPath, config?: RouteConfiguration<TPath, TInputParams, TOutputParams, TQueryParams>) => Route<TPath, TInputParams, TOutputParams, TQueryParams>;
478
494
 
479
495
  /**
480
496
  * Global configuration for routes and router.
@@ -504,7 +520,7 @@ interface RouterConfiguration<TRoutesStruct extends RoutesCollection> {
504
520
  history?: History;
505
521
  queryParams?: IQueryParams;
506
522
  }
507
- interface RouterNavigateOptions extends RouteNavigateParams {
523
+ interface RouterNavigateOptions<TQueryParams extends Record<string, any> = AnyObject> extends RouteNavigateParams<TQueryParams> {
508
524
  }
509
525
  type AnyRouter = Router<RoutesCollection>;
510
526
 
@@ -526,4 +542,4 @@ declare const createRouter: <TRoutesCollection extends RoutesCollection>(config:
526
542
  declare const isRouteEntity: (route: any) => route is AnyRouteEntity;
527
543
 
528
544
  export { Route, RouteGroup, Router, VirtualRoute, createRoute, createRouter, createVirtualRoute, groupRoutes, isRouteEntity, routeConfig };
529
- export type { AbstractRouteGroup, AbstractVirtualRoute, AnyAbstractRoute, AnyAbstractRouteEntity, AnyRoute, AnyRouteEntity, AnyRouteGroup, AnyRouter, AnyVirtualRoute, BeforeOpenFeedback, CreatedUrlOutputParams, InferInputParams, InferParams, InferPath, InputPathParam, InputPathParams, NavigationTrx, ParsedPathData, ParsedPathParam, ParsedPathParams, PathToObject, RouteConfiguration, RouteGlobalConfig, RouteNavigateParams, RouteParams, RouterConfiguration, RouterNavigateOptions, RoutesArrayCollection, RoutesCollection, RoutesObjectCollection, UrlCreateParams, UrlCreateParamsFn, VirtualOpenExtraParams, VirtualRouteConfiguration, VirtualRouteTrx };
545
+ export type { AbstractRouteGroup, AbstractVirtualRoute, AnyAbstractRoute, AnyAbstractRouteEntity, AnyRoute, AnyRouteEntity, AnyRouteGroup, AnyRouter, AnyVirtualRoute, BeforeOpenFeedback, CreatedUrlOutputParams, InferInputParams, InferParams, InferPath, InferQueryParams, InputPathParam, InputPathParams, NavigationTrx, ParsedPathData, ParsedPathParam, ParsedPathParams, PathToObject, RouteConfiguration, RouteGlobalConfig, RouteNavigateParams, RouteParams, RouterConfiguration, RouterNavigateOptions, RoutesArrayCollection, RoutesCollection, RoutesObjectCollection, UrlCreateParams, UrlCreateParamsFn, VirtualOpenExtraParams, VirtualRouteConfiguration, VirtualRouteTrx };
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "mobx-location-history";
2
- import { R, a, b, V, c, d, e, g, r } from "./virtual-route-Chv5K9C8.js";
2
+ import { R, a, b, V, c, d, e, g, r } from "./virtual-route-C21P-S6I.js";
3
3
  const isRouteEntity = (route) => route && "isOpened" in route;
4
4
  export {
5
5
  R as Route,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobx-route",
3
- "version": "1.3.3",
3
+ "version": "2.0.0",
4
4
  "keywords": [
5
5
  "mobx",
6
6
  "react",
@@ -67,13 +67,13 @@
67
67
  "require": "./view-model.cjs",
68
68
  "default": "./view-model.js"
69
69
  },
70
- "./virtual-route-Chv5K9C8": {
71
- "import": "./virtual-route-Chv5K9C8.js",
72
- "default": "./virtual-route-Chv5K9C8.js"
70
+ "./virtual-route-C21P-S6I": {
71
+ "import": "./virtual-route-C21P-S6I.js",
72
+ "default": "./virtual-route-C21P-S6I.js"
73
73
  },
74
- "./virtual-route-sU8rVTsu": {
75
- "require": "./virtual-route-sU8rVTsu.cjs",
76
- "default": "./virtual-route-sU8rVTsu.cjs"
74
+ "./virtual-route-DCnOqDz5": {
75
+ "require": "./virtual-route-DCnOqDz5.cjs",
76
+ "default": "./virtual-route-DCnOqDz5.cjs"
77
77
  }
78
78
  },
79
79
  "files": [
package/view-model.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const mobx = require("mobx");
4
4
  const mobxViewModel = require("mobx-view-model");
5
- const virtualRoute = require("./virtual-route-sU8rVTsu.cjs");
5
+ const virtualRoute = require("./virtual-route-DCnOqDz5.cjs");
6
6
  const annotations = [
7
7
  [mobx.computed.struct, "pathParams"],
8
8
  [mobx.computed, "query"]