@real-router/types 0.7.0 → 0.9.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/cjs/index.d.ts +64 -48
- package/dist/cjs/metafile-cjs.json +1 -1
- package/dist/esm/index.d.mts +64 -48
- package/dist/esm/metafile-esm.json +1 -1
- package/package.json +1 -1
package/dist/cjs/index.d.ts
CHANGED
|
@@ -151,55 +151,12 @@ interface NavigationOptions {
|
|
|
151
151
|
* @see {@link Router.areStatesEqual} for state comparison logic
|
|
152
152
|
*/
|
|
153
153
|
reload?: boolean | undefined;
|
|
154
|
-
/**
|
|
155
|
-
* Preview navigation without any side effects (dry-run mode).
|
|
156
|
-
*
|
|
157
|
-
* @description
|
|
158
|
-
* When `true`, returns the would-be target state via callback WITHOUT:
|
|
159
|
-
* - Executing canDeactivate/canActivate guards
|
|
160
|
-
* - Executing middleware
|
|
161
|
-
* - Updating router state (`router.getState()` remains unchanged)
|
|
162
|
-
* - Emitting any transition events (TRANSITION_START, TRANSITION_SUCCESS, etc.)
|
|
163
|
-
*
|
|
164
|
-
* The callback receives `(undefined, toState)` where `toState` is the computed
|
|
165
|
-
* target state that WOULD result from this navigation.
|
|
166
|
-
*
|
|
167
|
-
* @default false
|
|
168
|
-
*
|
|
169
|
-
* @remarks
|
|
170
|
-
* This option is useful for:
|
|
171
|
-
* - Validating that a route exists and params are correct
|
|
172
|
-
* - SSR: previewing state for pre-rendering without side effects
|
|
173
|
-
* - Dry-run before actual navigation
|
|
174
|
-
*
|
|
175
|
-
* @deprecated Consider using `router.buildState()` + `router.makeState()` instead
|
|
176
|
-
* for clearer intent. This option may be removed in a future major version.
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
179
|
-
* // Preview navigation - router.getState() is NOT changed
|
|
180
|
-
* router.navigate('users.view', { id: 123 }, { skipTransition: true }, (err, previewState) => {
|
|
181
|
-
* console.log(previewState); // { name: 'users.view', params: { id: 123 }, path: '/users/view/123', ... }
|
|
182
|
-
* console.log(router.getState()); // Still the previous state!
|
|
183
|
-
* });
|
|
184
|
-
*
|
|
185
|
-
* @example
|
|
186
|
-
* // Recommended alternative (clearer intent)
|
|
187
|
-
* const route = router.buildState('users.view', { id: 123 });
|
|
188
|
-
* if (route) {
|
|
189
|
-
* const path = router.buildPath(route.name, route.params);
|
|
190
|
-
* const previewState = router.makeState(route.name, route.params, path, { params: route.meta });
|
|
191
|
-
* }
|
|
192
|
-
*
|
|
193
|
-
* @see {@link forceDeactivate} for skipping only canDeactivate guards
|
|
194
|
-
* @see {@link force} for forcing navigation while preserving lifecycle
|
|
195
|
-
*/
|
|
196
|
-
skipTransition?: boolean | undefined;
|
|
197
154
|
/**
|
|
198
155
|
* Force navigation even if target state equals current state.
|
|
199
156
|
*
|
|
200
157
|
* @description
|
|
201
158
|
* When `true`, bypasses the "same state" equality check but still executes the full
|
|
202
|
-
* transition lifecycle
|
|
159
|
+
* transition lifecycle. Similar to `reload` but can be used
|
|
203
160
|
* for any forced navigation scenario.
|
|
204
161
|
*
|
|
205
162
|
* Difference from `reload`:
|
|
@@ -218,7 +175,6 @@ interface NavigationOptions {
|
|
|
218
175
|
* router.navigate('analytics', { event: 'pageview' }, { force: true });
|
|
219
176
|
*
|
|
220
177
|
* @see {@link reload} for semantic equivalent (preferred for refresh scenarios)
|
|
221
|
-
* @see {@link skipTransition} for bypassing entire lifecycle
|
|
222
178
|
*/
|
|
223
179
|
force?: boolean | undefined;
|
|
224
180
|
/**
|
|
@@ -251,7 +207,6 @@ interface NavigationOptions {
|
|
|
251
207
|
* });
|
|
252
208
|
* }
|
|
253
209
|
*
|
|
254
|
-
* @see {@link skipTransition} for bypassing all guards and middleware
|
|
255
210
|
* @see {@link Router.clearCanDeactivate} for programmatically clearing guards
|
|
256
211
|
*/
|
|
257
212
|
forceDeactivate?: boolean | undefined;
|
|
@@ -278,7 +233,7 @@ interface NavigationOptions {
|
|
|
278
233
|
*
|
|
279
234
|
* @example
|
|
280
235
|
* // Accessing redirect flag in lifecycle
|
|
281
|
-
* router.
|
|
236
|
+
* router.addActivateGuard('dashboard', (toState, fromState) => {
|
|
282
237
|
* if (toState.meta?.redirected) {
|
|
283
238
|
* console.log('This navigation is from a redirect');
|
|
284
239
|
* }
|
|
@@ -505,8 +460,69 @@ interface Navigator {
|
|
|
505
460
|
navigate: (routeName: string, routeParamsOrDone?: Params | DoneFn, optionsOrDone?: NavigationOptions | DoneFn, done?: DoneFn) => CancelFn;
|
|
506
461
|
getState: () => State | undefined;
|
|
507
462
|
isActiveRoute: (name: string, params?: Params, strictEquality?: boolean, ignoreQueryParams?: boolean) => boolean;
|
|
463
|
+
canNavigateTo: (name: string, params?: Params) => boolean;
|
|
508
464
|
subscribe: (listener: SubscribeFn) => Unsubscribe;
|
|
509
465
|
}
|
|
466
|
+
/**
|
|
467
|
+
* Router interface - public API for route navigation and lifecycle management.
|
|
468
|
+
*
|
|
469
|
+
* Defines the contract for router implementations. The actual Router class in
|
|
470
|
+
* @real-router/core implements this interface with full functionality.
|
|
471
|
+
*
|
|
472
|
+
* This interface uses `ActivationFn | boolean` for guard types to avoid circular
|
|
473
|
+
* dependencies. The concrete Router class in @real-router/core narrows this to
|
|
474
|
+
* `ActivationFnFactory | boolean` for more precise type checking.
|
|
475
|
+
*/
|
|
476
|
+
interface Router {
|
|
477
|
+
/**
|
|
478
|
+
* Register an activation guard for a route.
|
|
479
|
+
*
|
|
480
|
+
* @param name - Route name
|
|
481
|
+
* @param guard - Guard function or boolean
|
|
482
|
+
* @returns this for method chaining
|
|
483
|
+
*/
|
|
484
|
+
addActivateGuard: (name: string, guard: ActivationFn | boolean) => this;
|
|
485
|
+
/**
|
|
486
|
+
* Register a deactivation guard for a route.
|
|
487
|
+
*
|
|
488
|
+
* @param name - Route name
|
|
489
|
+
* @param guard - Guard function or boolean
|
|
490
|
+
* @returns this for method chaining
|
|
491
|
+
*/
|
|
492
|
+
addDeactivateGuard: (name: string, guard: ActivationFn | boolean) => this;
|
|
493
|
+
/**
|
|
494
|
+
* Remove an activation guard from a route.
|
|
495
|
+
*
|
|
496
|
+
* @param name - Route name
|
|
497
|
+
*/
|
|
498
|
+
removeActivateGuard: (name: string) => void;
|
|
499
|
+
/**
|
|
500
|
+
* Remove a deactivation guard from a route.
|
|
501
|
+
*
|
|
502
|
+
* @param name - Route name
|
|
503
|
+
*/
|
|
504
|
+
removeDeactivateGuard: (name: string) => void;
|
|
505
|
+
/**
|
|
506
|
+
* Check if navigation to a route is allowed without performing actual navigation.
|
|
507
|
+
*
|
|
508
|
+
* Synchronously checks all activation and deactivation guards in the transition path.
|
|
509
|
+
* Async guards return false with a console warning.
|
|
510
|
+
*
|
|
511
|
+
* @param name - Route name to check
|
|
512
|
+
* @param params - Route parameters (optional)
|
|
513
|
+
* @returns true if navigation is allowed, false otherwise
|
|
514
|
+
*/
|
|
515
|
+
canNavigateTo: (name: string, params?: Params) => boolean;
|
|
516
|
+
/**
|
|
517
|
+
* Get a minimal, safe Navigator interface for passing to components.
|
|
518
|
+
*
|
|
519
|
+
* The returned Navigator object is frozen and includes only essential methods:
|
|
520
|
+
* navigate, getState, isActiveRoute, canNavigateTo, subscribe.
|
|
521
|
+
*
|
|
522
|
+
* @returns Frozen Navigator object
|
|
523
|
+
*/
|
|
524
|
+
getNavigator: () => Navigator;
|
|
525
|
+
}
|
|
510
526
|
|
|
511
527
|
/**
|
|
512
528
|
* Plugin lifecycle method names
|
|
@@ -565,4 +581,4 @@ interface ErrorCodeToValueMap {
|
|
|
565
581
|
TRANSITION_CANCELLED: "CANCELLED";
|
|
566
582
|
}
|
|
567
583
|
|
|
568
|
-
export type { ActivationFn, CancelFn, Config, DefaultDependencies, DefaultParamsCallback, DefaultRouteCallback, DoneFn, ErrorCodeKeys, ErrorCodeToValueMap, ErrorCodeValues, EventName, EventToNameMap, EventToPluginMap, EventsKeys, ForwardToCallback, LimitsConfig, Listener, Middleware, NavigationOptions, Navigator, Options, Params, Plugin, PluginMethod, QueryParamsMode, QueryParamsOptions, RouteTreeState, RouterError, SimpleState, State, StateMeta, StateMetaInput, SubscribeFn, SubscribeState, Subscription, Unsubscribe };
|
|
584
|
+
export type { ActivationFn, CancelFn, Config, DefaultDependencies, DefaultParamsCallback, DefaultRouteCallback, DoneFn, ErrorCodeKeys, ErrorCodeToValueMap, ErrorCodeValues, EventName, EventToNameMap, EventToPluginMap, EventsKeys, ForwardToCallback, LimitsConfig, Listener, Middleware, NavigationOptions, Navigator, Options, Params, Plugin, PluginMethod, QueryParamsMode, QueryParamsOptions, RouteTreeState, Router, RouterError, SimpleState, State, StateMeta, StateMetaInput, SubscribeFn, SubscribeState, Subscription, Unsubscribe };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js":{"bytes":569,"imports":[],"format":"esm"},"src/index.ts":{"bytes":
|
|
1
|
+
{"inputs":{"../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js":{"bytes":569,"imports":[],"format":"esm"},"src/index.ts":{"bytes":1248,"imports":[{"path":"/home/runner/work/real-router/real-router/node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"dist/cjs/index.js":{"imports":[],"exports":[],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":0}},"bytes":0}}}
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -151,55 +151,12 @@ interface NavigationOptions {
|
|
|
151
151
|
* @see {@link Router.areStatesEqual} for state comparison logic
|
|
152
152
|
*/
|
|
153
153
|
reload?: boolean | undefined;
|
|
154
|
-
/**
|
|
155
|
-
* Preview navigation without any side effects (dry-run mode).
|
|
156
|
-
*
|
|
157
|
-
* @description
|
|
158
|
-
* When `true`, returns the would-be target state via callback WITHOUT:
|
|
159
|
-
* - Executing canDeactivate/canActivate guards
|
|
160
|
-
* - Executing middleware
|
|
161
|
-
* - Updating router state (`router.getState()` remains unchanged)
|
|
162
|
-
* - Emitting any transition events (TRANSITION_START, TRANSITION_SUCCESS, etc.)
|
|
163
|
-
*
|
|
164
|
-
* The callback receives `(undefined, toState)` where `toState` is the computed
|
|
165
|
-
* target state that WOULD result from this navigation.
|
|
166
|
-
*
|
|
167
|
-
* @default false
|
|
168
|
-
*
|
|
169
|
-
* @remarks
|
|
170
|
-
* This option is useful for:
|
|
171
|
-
* - Validating that a route exists and params are correct
|
|
172
|
-
* - SSR: previewing state for pre-rendering without side effects
|
|
173
|
-
* - Dry-run before actual navigation
|
|
174
|
-
*
|
|
175
|
-
* @deprecated Consider using `router.buildState()` + `router.makeState()` instead
|
|
176
|
-
* for clearer intent. This option may be removed in a future major version.
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
179
|
-
* // Preview navigation - router.getState() is NOT changed
|
|
180
|
-
* router.navigate('users.view', { id: 123 }, { skipTransition: true }, (err, previewState) => {
|
|
181
|
-
* console.log(previewState); // { name: 'users.view', params: { id: 123 }, path: '/users/view/123', ... }
|
|
182
|
-
* console.log(router.getState()); // Still the previous state!
|
|
183
|
-
* });
|
|
184
|
-
*
|
|
185
|
-
* @example
|
|
186
|
-
* // Recommended alternative (clearer intent)
|
|
187
|
-
* const route = router.buildState('users.view', { id: 123 });
|
|
188
|
-
* if (route) {
|
|
189
|
-
* const path = router.buildPath(route.name, route.params);
|
|
190
|
-
* const previewState = router.makeState(route.name, route.params, path, { params: route.meta });
|
|
191
|
-
* }
|
|
192
|
-
*
|
|
193
|
-
* @see {@link forceDeactivate} for skipping only canDeactivate guards
|
|
194
|
-
* @see {@link force} for forcing navigation while preserving lifecycle
|
|
195
|
-
*/
|
|
196
|
-
skipTransition?: boolean | undefined;
|
|
197
154
|
/**
|
|
198
155
|
* Force navigation even if target state equals current state.
|
|
199
156
|
*
|
|
200
157
|
* @description
|
|
201
158
|
* When `true`, bypasses the "same state" equality check but still executes the full
|
|
202
|
-
* transition lifecycle
|
|
159
|
+
* transition lifecycle. Similar to `reload` but can be used
|
|
203
160
|
* for any forced navigation scenario.
|
|
204
161
|
*
|
|
205
162
|
* Difference from `reload`:
|
|
@@ -218,7 +175,6 @@ interface NavigationOptions {
|
|
|
218
175
|
* router.navigate('analytics', { event: 'pageview' }, { force: true });
|
|
219
176
|
*
|
|
220
177
|
* @see {@link reload} for semantic equivalent (preferred for refresh scenarios)
|
|
221
|
-
* @see {@link skipTransition} for bypassing entire lifecycle
|
|
222
178
|
*/
|
|
223
179
|
force?: boolean | undefined;
|
|
224
180
|
/**
|
|
@@ -251,7 +207,6 @@ interface NavigationOptions {
|
|
|
251
207
|
* });
|
|
252
208
|
* }
|
|
253
209
|
*
|
|
254
|
-
* @see {@link skipTransition} for bypassing all guards and middleware
|
|
255
210
|
* @see {@link Router.clearCanDeactivate} for programmatically clearing guards
|
|
256
211
|
*/
|
|
257
212
|
forceDeactivate?: boolean | undefined;
|
|
@@ -278,7 +233,7 @@ interface NavigationOptions {
|
|
|
278
233
|
*
|
|
279
234
|
* @example
|
|
280
235
|
* // Accessing redirect flag in lifecycle
|
|
281
|
-
* router.
|
|
236
|
+
* router.addActivateGuard('dashboard', (toState, fromState) => {
|
|
282
237
|
* if (toState.meta?.redirected) {
|
|
283
238
|
* console.log('This navigation is from a redirect');
|
|
284
239
|
* }
|
|
@@ -505,8 +460,69 @@ interface Navigator {
|
|
|
505
460
|
navigate: (routeName: string, routeParamsOrDone?: Params | DoneFn, optionsOrDone?: NavigationOptions | DoneFn, done?: DoneFn) => CancelFn;
|
|
506
461
|
getState: () => State | undefined;
|
|
507
462
|
isActiveRoute: (name: string, params?: Params, strictEquality?: boolean, ignoreQueryParams?: boolean) => boolean;
|
|
463
|
+
canNavigateTo: (name: string, params?: Params) => boolean;
|
|
508
464
|
subscribe: (listener: SubscribeFn) => Unsubscribe;
|
|
509
465
|
}
|
|
466
|
+
/**
|
|
467
|
+
* Router interface - public API for route navigation and lifecycle management.
|
|
468
|
+
*
|
|
469
|
+
* Defines the contract for router implementations. The actual Router class in
|
|
470
|
+
* @real-router/core implements this interface with full functionality.
|
|
471
|
+
*
|
|
472
|
+
* This interface uses `ActivationFn | boolean` for guard types to avoid circular
|
|
473
|
+
* dependencies. The concrete Router class in @real-router/core narrows this to
|
|
474
|
+
* `ActivationFnFactory | boolean` for more precise type checking.
|
|
475
|
+
*/
|
|
476
|
+
interface Router {
|
|
477
|
+
/**
|
|
478
|
+
* Register an activation guard for a route.
|
|
479
|
+
*
|
|
480
|
+
* @param name - Route name
|
|
481
|
+
* @param guard - Guard function or boolean
|
|
482
|
+
* @returns this for method chaining
|
|
483
|
+
*/
|
|
484
|
+
addActivateGuard: (name: string, guard: ActivationFn | boolean) => this;
|
|
485
|
+
/**
|
|
486
|
+
* Register a deactivation guard for a route.
|
|
487
|
+
*
|
|
488
|
+
* @param name - Route name
|
|
489
|
+
* @param guard - Guard function or boolean
|
|
490
|
+
* @returns this for method chaining
|
|
491
|
+
*/
|
|
492
|
+
addDeactivateGuard: (name: string, guard: ActivationFn | boolean) => this;
|
|
493
|
+
/**
|
|
494
|
+
* Remove an activation guard from a route.
|
|
495
|
+
*
|
|
496
|
+
* @param name - Route name
|
|
497
|
+
*/
|
|
498
|
+
removeActivateGuard: (name: string) => void;
|
|
499
|
+
/**
|
|
500
|
+
* Remove a deactivation guard from a route.
|
|
501
|
+
*
|
|
502
|
+
* @param name - Route name
|
|
503
|
+
*/
|
|
504
|
+
removeDeactivateGuard: (name: string) => void;
|
|
505
|
+
/**
|
|
506
|
+
* Check if navigation to a route is allowed without performing actual navigation.
|
|
507
|
+
*
|
|
508
|
+
* Synchronously checks all activation and deactivation guards in the transition path.
|
|
509
|
+
* Async guards return false with a console warning.
|
|
510
|
+
*
|
|
511
|
+
* @param name - Route name to check
|
|
512
|
+
* @param params - Route parameters (optional)
|
|
513
|
+
* @returns true if navigation is allowed, false otherwise
|
|
514
|
+
*/
|
|
515
|
+
canNavigateTo: (name: string, params?: Params) => boolean;
|
|
516
|
+
/**
|
|
517
|
+
* Get a minimal, safe Navigator interface for passing to components.
|
|
518
|
+
*
|
|
519
|
+
* The returned Navigator object is frozen and includes only essential methods:
|
|
520
|
+
* navigate, getState, isActiveRoute, canNavigateTo, subscribe.
|
|
521
|
+
*
|
|
522
|
+
* @returns Frozen Navigator object
|
|
523
|
+
*/
|
|
524
|
+
getNavigator: () => Navigator;
|
|
525
|
+
}
|
|
510
526
|
|
|
511
527
|
/**
|
|
512
528
|
* Plugin lifecycle method names
|
|
@@ -565,4 +581,4 @@ interface ErrorCodeToValueMap {
|
|
|
565
581
|
TRANSITION_CANCELLED: "CANCELLED";
|
|
566
582
|
}
|
|
567
583
|
|
|
568
|
-
export type { ActivationFn, CancelFn, Config, DefaultDependencies, DefaultParamsCallback, DefaultRouteCallback, DoneFn, ErrorCodeKeys, ErrorCodeToValueMap, ErrorCodeValues, EventName, EventToNameMap, EventToPluginMap, EventsKeys, ForwardToCallback, LimitsConfig, Listener, Middleware, NavigationOptions, Navigator, Options, Params, Plugin, PluginMethod, QueryParamsMode, QueryParamsOptions, RouteTreeState, RouterError, SimpleState, State, StateMeta, StateMetaInput, SubscribeFn, SubscribeState, Subscription, Unsubscribe };
|
|
584
|
+
export type { ActivationFn, CancelFn, Config, DefaultDependencies, DefaultParamsCallback, DefaultRouteCallback, DoneFn, ErrorCodeKeys, ErrorCodeToValueMap, ErrorCodeValues, EventName, EventToNameMap, EventToPluginMap, EventsKeys, ForwardToCallback, LimitsConfig, Listener, Middleware, NavigationOptions, Navigator, Options, Params, Plugin, PluginMethod, QueryParamsMode, QueryParamsOptions, RouteTreeState, Router, RouterError, SimpleState, State, StateMeta, StateMetaInput, SubscribeFn, SubscribeState, Subscription, Unsubscribe };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/index.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/index.ts":{"bytes":1248,"imports":[],"format":"esm"}},"outputs":{"dist/esm/index.mjs":{"imports":[],"exports":[],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":0}},"bytes":0}}}
|