@real-router/types 0.13.0 → 0.15.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 +16 -32
- package/dist/cjs/metafile-cjs.json +1 -1
- package/dist/esm/index.d.mts +16 -32
- package/dist/esm/metafile-esm.json +1 -1
- package/package.json +1 -1
- package/src/base.ts +8 -17
- package/src/index.ts +2 -2
- package/src/limits.ts +0 -8
- package/src/router.ts +11 -9
package/dist/cjs/index.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ interface SimpleState<P extends Params = Params> {
|
|
|
44
44
|
name: string;
|
|
45
45
|
params: P;
|
|
46
46
|
}
|
|
47
|
-
type TransitionPhase = "deactivating" | "activating"
|
|
47
|
+
type TransitionPhase = "deactivating" | "activating";
|
|
48
48
|
type TransitionReason = "success" | "blocked" | "cancelled" | "error";
|
|
49
49
|
interface TransitionMeta {
|
|
50
50
|
phase: TransitionPhase;
|
|
@@ -103,7 +103,7 @@ interface RouterError extends Error {
|
|
|
103
103
|
*
|
|
104
104
|
* All options are optional and have sensible defaults. Options can be combined to achieve
|
|
105
105
|
* complex navigation behaviors. The options object is stored in state.meta.options and is
|
|
106
|
-
* available to
|
|
106
|
+
* available to guards and event listeners.
|
|
107
107
|
*
|
|
108
108
|
* @see {@link Router.navigate} for navigation method that accepts these options
|
|
109
109
|
* @see {@link State.meta} for where options are stored after navigation
|
|
@@ -137,11 +137,11 @@ interface NavigationOptions {
|
|
|
137
137
|
*
|
|
138
138
|
* Without `reload`:
|
|
139
139
|
* - Navigation to current route throws SAME_STATES error
|
|
140
|
-
* - No lifecycle hooks
|
|
140
|
+
* - No lifecycle hooks execute
|
|
141
141
|
* - No events are fired
|
|
142
142
|
*
|
|
143
143
|
* With `reload`:
|
|
144
|
-
* - Full transition executes (deactivate → activate
|
|
144
|
+
* - Full transition executes (deactivate → activate)
|
|
145
145
|
* - All lifecycle hooks run again
|
|
146
146
|
* - TRANSITION_SUCCESS event fires with same state
|
|
147
147
|
* - State object is recreated (new reference)
|
|
@@ -192,16 +192,16 @@ interface NavigationOptions {
|
|
|
192
192
|
*
|
|
193
193
|
* @description
|
|
194
194
|
* When `true`, bypasses only the canDeactivate lifecycle hooks for segments being
|
|
195
|
-
* deactivated. canActivate guards
|
|
195
|
+
* deactivated. canActivate guards still execute normally. This allows
|
|
196
196
|
* forcing navigation away from routes with confirmation dialogs or unsaved changes.
|
|
197
197
|
*
|
|
198
198
|
* Skipped vs executed:
|
|
199
199
|
* ```
|
|
200
200
|
* // Normal transition
|
|
201
|
-
* deactivate(fromSegments) → activate(toSegments) →
|
|
201
|
+
* deactivate(fromSegments) → activate(toSegments) → success
|
|
202
202
|
*
|
|
203
203
|
* // With forceDeactivate: true
|
|
204
|
-
* [skip deactivate] → activate(toSegments) →
|
|
204
|
+
* [skip deactivate] → activate(toSegments) → success
|
|
205
205
|
* ```
|
|
206
206
|
*
|
|
207
207
|
* ⚠️ Data loss risk: Bypassing canDeactivate means unsaved changes will be lost
|
|
@@ -227,21 +227,12 @@ interface NavigationOptions {
|
|
|
227
227
|
*
|
|
228
228
|
* @description
|
|
229
229
|
* Automatically set by the router when a navigation is triggered by a redirect from
|
|
230
|
-
*
|
|
230
|
+
* guards or lifecycle hooks. This flag is used internally to track redirect chains
|
|
231
231
|
* and is stored in state.meta.options.redirected.
|
|
232
232
|
*
|
|
233
233
|
* @default false (auto-set by router during redirects)
|
|
234
234
|
*
|
|
235
235
|
* @example
|
|
236
|
-
* // Middleware triggers automatic redirect
|
|
237
|
-
* router.useMiddleware((toState, fromState, opts) => {
|
|
238
|
-
* if (!isAuthenticated && toState.name !== 'login') {
|
|
239
|
-
* // Router will automatically set redirected: true
|
|
240
|
-
* return { name: 'login', params: { next: toState.path } };
|
|
241
|
-
* }
|
|
242
|
-
* });
|
|
243
|
-
*
|
|
244
|
-
* @example
|
|
245
236
|
* // Accessing redirect flag in lifecycle
|
|
246
237
|
* router.addActivateGuard('dashboard', (toState, fromState) => {
|
|
247
238
|
* if (toState.meta?.options?.redirected) {
|
|
@@ -278,13 +269,6 @@ interface LimitsConfig {
|
|
|
278
269
|
* @default 50
|
|
279
270
|
*/
|
|
280
271
|
maxPlugins: number;
|
|
281
|
-
/**
|
|
282
|
-
* Maximum number of middleware functions in the navigation pipeline.
|
|
283
|
-
* Controls middleware chain length to prevent stack overflow and performance issues.
|
|
284
|
-
*
|
|
285
|
-
* @default 50
|
|
286
|
-
*/
|
|
287
|
-
maxMiddleware: number;
|
|
288
272
|
/**
|
|
289
273
|
* Maximum number of event listeners per event type.
|
|
290
274
|
* Prevents memory leaks from excessive listener registration.
|
|
@@ -319,7 +303,7 @@ interface LimitsConfig {
|
|
|
319
303
|
* Base router types without Router class dependency.
|
|
320
304
|
*
|
|
321
305
|
* Router-dependent types (Route, RouteConfigUpdate, ActivationFnFactory,
|
|
322
|
-
*
|
|
306
|
+
* PluginFactory) are defined in @real-router/core
|
|
323
307
|
* to avoid circular dependencies.
|
|
324
308
|
*/
|
|
325
309
|
|
|
@@ -433,6 +417,7 @@ interface Options {
|
|
|
433
417
|
noValidate?: boolean;
|
|
434
418
|
}
|
|
435
419
|
type ActivationFn = (toState: State, fromState: State | undefined) => boolean | Promise<boolean | State | void> | State | void;
|
|
420
|
+
type GuardFn = (toState: State, fromState: State | undefined) => boolean | Promise<boolean>;
|
|
436
421
|
type DefaultDependencies = object;
|
|
437
422
|
interface Config {
|
|
438
423
|
decoders: Record<string, (params: Params) => Params>;
|
|
@@ -449,7 +434,6 @@ interface Plugin {
|
|
|
449
434
|
onTransitionSuccess?: (toState: State, fromState: State | undefined, opts: NavigationOptions) => void;
|
|
450
435
|
teardown?: () => void;
|
|
451
436
|
}
|
|
452
|
-
type Middleware = ActivationFn;
|
|
453
437
|
interface SubscribeState {
|
|
454
438
|
route: State;
|
|
455
439
|
previousRoute?: State | undefined;
|
|
@@ -486,9 +470,9 @@ interface Navigator {
|
|
|
486
470
|
* Defines the contract for router implementations. The actual Router class in
|
|
487
471
|
* @real-router/core implements this interface with full functionality.
|
|
488
472
|
*
|
|
489
|
-
* This interface uses `
|
|
473
|
+
* This interface uses `GuardFn | boolean` for guard types to avoid circular
|
|
490
474
|
* dependencies. The concrete Router class in @real-router/core narrows this to
|
|
491
|
-
* `
|
|
475
|
+
* `GuardFnFactory | boolean` for more precise type checking.
|
|
492
476
|
*/
|
|
493
477
|
interface Router {
|
|
494
478
|
/**
|
|
@@ -498,7 +482,7 @@ interface Router {
|
|
|
498
482
|
* @param guard - Guard function or boolean
|
|
499
483
|
* @returns this for method chaining
|
|
500
484
|
*/
|
|
501
|
-
addActivateGuard: (name: string, guard:
|
|
485
|
+
addActivateGuard: (name: string, guard: GuardFn | boolean) => this;
|
|
502
486
|
/**
|
|
503
487
|
* Register a deactivation guard for a route.
|
|
504
488
|
*
|
|
@@ -506,7 +490,7 @@ interface Router {
|
|
|
506
490
|
* @param guard - Guard function or boolean
|
|
507
491
|
* @returns this for method chaining
|
|
508
492
|
*/
|
|
509
|
-
addDeactivateGuard: (name: string, guard:
|
|
493
|
+
addDeactivateGuard: (name: string, guard: GuardFn | boolean) => this;
|
|
510
494
|
/**
|
|
511
495
|
* Remove an activation guard from a route.
|
|
512
496
|
*
|
|
@@ -534,7 +518,7 @@ interface Router {
|
|
|
534
518
|
* Dispose the router and release all resources.
|
|
535
519
|
*
|
|
536
520
|
* Stops the router if active, calls plugin teardown, clears all event
|
|
537
|
-
* listeners,
|
|
521
|
+
* listeners, routes, and dependencies. After disposal, all
|
|
538
522
|
* mutating methods throw a ROUTER_DISPOSED error. Idempotent — safe to
|
|
539
523
|
* call multiple times.
|
|
540
524
|
*/
|
|
@@ -599,4 +583,4 @@ interface ErrorCodeToValueMap {
|
|
|
599
583
|
ROUTER_DISPOSED: "DISPOSED";
|
|
600
584
|
}
|
|
601
585
|
|
|
602
|
-
export type { ActivationFn, Config, DefaultDependencies, DefaultParamsCallback, DefaultRouteCallback, ErrorCodeKeys, ErrorCodeToValueMap, ErrorCodeValues, EventName, EventToNameMap, EventToPluginMap, EventsKeys, ForwardToCallback, LimitsConfig, Listener,
|
|
586
|
+
export type { ActivationFn, Config, DefaultDependencies, DefaultParamsCallback, DefaultRouteCallback, ErrorCodeKeys, ErrorCodeToValueMap, ErrorCodeValues, EventName, EventToNameMap, EventToPluginMap, EventsKeys, ForwardToCallback, GuardFn, LimitsConfig, Listener, NavigationOptions, Navigator, Options, Params, Plugin, PluginMethod, QueryParamsMode, QueryParamsOptions, RouteParams, RouteTreeState, Router, RouterError, SimpleState, State, StateMeta, StateMetaInput, SubscribeFn, SubscribeState, Subscription, TransitionMeta, TransitionPhase, TransitionReason, 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":1276,"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
|
@@ -44,7 +44,7 @@ interface SimpleState<P extends Params = Params> {
|
|
|
44
44
|
name: string;
|
|
45
45
|
params: P;
|
|
46
46
|
}
|
|
47
|
-
type TransitionPhase = "deactivating" | "activating"
|
|
47
|
+
type TransitionPhase = "deactivating" | "activating";
|
|
48
48
|
type TransitionReason = "success" | "blocked" | "cancelled" | "error";
|
|
49
49
|
interface TransitionMeta {
|
|
50
50
|
phase: TransitionPhase;
|
|
@@ -103,7 +103,7 @@ interface RouterError extends Error {
|
|
|
103
103
|
*
|
|
104
104
|
* All options are optional and have sensible defaults. Options can be combined to achieve
|
|
105
105
|
* complex navigation behaviors. The options object is stored in state.meta.options and is
|
|
106
|
-
* available to
|
|
106
|
+
* available to guards and event listeners.
|
|
107
107
|
*
|
|
108
108
|
* @see {@link Router.navigate} for navigation method that accepts these options
|
|
109
109
|
* @see {@link State.meta} for where options are stored after navigation
|
|
@@ -137,11 +137,11 @@ interface NavigationOptions {
|
|
|
137
137
|
*
|
|
138
138
|
* Without `reload`:
|
|
139
139
|
* - Navigation to current route throws SAME_STATES error
|
|
140
|
-
* - No lifecycle hooks
|
|
140
|
+
* - No lifecycle hooks execute
|
|
141
141
|
* - No events are fired
|
|
142
142
|
*
|
|
143
143
|
* With `reload`:
|
|
144
|
-
* - Full transition executes (deactivate → activate
|
|
144
|
+
* - Full transition executes (deactivate → activate)
|
|
145
145
|
* - All lifecycle hooks run again
|
|
146
146
|
* - TRANSITION_SUCCESS event fires with same state
|
|
147
147
|
* - State object is recreated (new reference)
|
|
@@ -192,16 +192,16 @@ interface NavigationOptions {
|
|
|
192
192
|
*
|
|
193
193
|
* @description
|
|
194
194
|
* When `true`, bypasses only the canDeactivate lifecycle hooks for segments being
|
|
195
|
-
* deactivated. canActivate guards
|
|
195
|
+
* deactivated. canActivate guards still execute normally. This allows
|
|
196
196
|
* forcing navigation away from routes with confirmation dialogs or unsaved changes.
|
|
197
197
|
*
|
|
198
198
|
* Skipped vs executed:
|
|
199
199
|
* ```
|
|
200
200
|
* // Normal transition
|
|
201
|
-
* deactivate(fromSegments) → activate(toSegments) →
|
|
201
|
+
* deactivate(fromSegments) → activate(toSegments) → success
|
|
202
202
|
*
|
|
203
203
|
* // With forceDeactivate: true
|
|
204
|
-
* [skip deactivate] → activate(toSegments) →
|
|
204
|
+
* [skip deactivate] → activate(toSegments) → success
|
|
205
205
|
* ```
|
|
206
206
|
*
|
|
207
207
|
* ⚠️ Data loss risk: Bypassing canDeactivate means unsaved changes will be lost
|
|
@@ -227,21 +227,12 @@ interface NavigationOptions {
|
|
|
227
227
|
*
|
|
228
228
|
* @description
|
|
229
229
|
* Automatically set by the router when a navigation is triggered by a redirect from
|
|
230
|
-
*
|
|
230
|
+
* guards or lifecycle hooks. This flag is used internally to track redirect chains
|
|
231
231
|
* and is stored in state.meta.options.redirected.
|
|
232
232
|
*
|
|
233
233
|
* @default false (auto-set by router during redirects)
|
|
234
234
|
*
|
|
235
235
|
* @example
|
|
236
|
-
* // Middleware triggers automatic redirect
|
|
237
|
-
* router.useMiddleware((toState, fromState, opts) => {
|
|
238
|
-
* if (!isAuthenticated && toState.name !== 'login') {
|
|
239
|
-
* // Router will automatically set redirected: true
|
|
240
|
-
* return { name: 'login', params: { next: toState.path } };
|
|
241
|
-
* }
|
|
242
|
-
* });
|
|
243
|
-
*
|
|
244
|
-
* @example
|
|
245
236
|
* // Accessing redirect flag in lifecycle
|
|
246
237
|
* router.addActivateGuard('dashboard', (toState, fromState) => {
|
|
247
238
|
* if (toState.meta?.options?.redirected) {
|
|
@@ -278,13 +269,6 @@ interface LimitsConfig {
|
|
|
278
269
|
* @default 50
|
|
279
270
|
*/
|
|
280
271
|
maxPlugins: number;
|
|
281
|
-
/**
|
|
282
|
-
* Maximum number of middleware functions in the navigation pipeline.
|
|
283
|
-
* Controls middleware chain length to prevent stack overflow and performance issues.
|
|
284
|
-
*
|
|
285
|
-
* @default 50
|
|
286
|
-
*/
|
|
287
|
-
maxMiddleware: number;
|
|
288
272
|
/**
|
|
289
273
|
* Maximum number of event listeners per event type.
|
|
290
274
|
* Prevents memory leaks from excessive listener registration.
|
|
@@ -319,7 +303,7 @@ interface LimitsConfig {
|
|
|
319
303
|
* Base router types without Router class dependency.
|
|
320
304
|
*
|
|
321
305
|
* Router-dependent types (Route, RouteConfigUpdate, ActivationFnFactory,
|
|
322
|
-
*
|
|
306
|
+
* PluginFactory) are defined in @real-router/core
|
|
323
307
|
* to avoid circular dependencies.
|
|
324
308
|
*/
|
|
325
309
|
|
|
@@ -433,6 +417,7 @@ interface Options {
|
|
|
433
417
|
noValidate?: boolean;
|
|
434
418
|
}
|
|
435
419
|
type ActivationFn = (toState: State, fromState: State | undefined) => boolean | Promise<boolean | State | void> | State | void;
|
|
420
|
+
type GuardFn = (toState: State, fromState: State | undefined) => boolean | Promise<boolean>;
|
|
436
421
|
type DefaultDependencies = object;
|
|
437
422
|
interface Config {
|
|
438
423
|
decoders: Record<string, (params: Params) => Params>;
|
|
@@ -449,7 +434,6 @@ interface Plugin {
|
|
|
449
434
|
onTransitionSuccess?: (toState: State, fromState: State | undefined, opts: NavigationOptions) => void;
|
|
450
435
|
teardown?: () => void;
|
|
451
436
|
}
|
|
452
|
-
type Middleware = ActivationFn;
|
|
453
437
|
interface SubscribeState {
|
|
454
438
|
route: State;
|
|
455
439
|
previousRoute?: State | undefined;
|
|
@@ -486,9 +470,9 @@ interface Navigator {
|
|
|
486
470
|
* Defines the contract for router implementations. The actual Router class in
|
|
487
471
|
* @real-router/core implements this interface with full functionality.
|
|
488
472
|
*
|
|
489
|
-
* This interface uses `
|
|
473
|
+
* This interface uses `GuardFn | boolean` for guard types to avoid circular
|
|
490
474
|
* dependencies. The concrete Router class in @real-router/core narrows this to
|
|
491
|
-
* `
|
|
475
|
+
* `GuardFnFactory | boolean` for more precise type checking.
|
|
492
476
|
*/
|
|
493
477
|
interface Router {
|
|
494
478
|
/**
|
|
@@ -498,7 +482,7 @@ interface Router {
|
|
|
498
482
|
* @param guard - Guard function or boolean
|
|
499
483
|
* @returns this for method chaining
|
|
500
484
|
*/
|
|
501
|
-
addActivateGuard: (name: string, guard:
|
|
485
|
+
addActivateGuard: (name: string, guard: GuardFn | boolean) => this;
|
|
502
486
|
/**
|
|
503
487
|
* Register a deactivation guard for a route.
|
|
504
488
|
*
|
|
@@ -506,7 +490,7 @@ interface Router {
|
|
|
506
490
|
* @param guard - Guard function or boolean
|
|
507
491
|
* @returns this for method chaining
|
|
508
492
|
*/
|
|
509
|
-
addDeactivateGuard: (name: string, guard:
|
|
493
|
+
addDeactivateGuard: (name: string, guard: GuardFn | boolean) => this;
|
|
510
494
|
/**
|
|
511
495
|
* Remove an activation guard from a route.
|
|
512
496
|
*
|
|
@@ -534,7 +518,7 @@ interface Router {
|
|
|
534
518
|
* Dispose the router and release all resources.
|
|
535
519
|
*
|
|
536
520
|
* Stops the router if active, calls plugin teardown, clears all event
|
|
537
|
-
* listeners,
|
|
521
|
+
* listeners, routes, and dependencies. After disposal, all
|
|
538
522
|
* mutating methods throw a ROUTER_DISPOSED error. Idempotent — safe to
|
|
539
523
|
* call multiple times.
|
|
540
524
|
*/
|
|
@@ -599,4 +583,4 @@ interface ErrorCodeToValueMap {
|
|
|
599
583
|
ROUTER_DISPOSED: "DISPOSED";
|
|
600
584
|
}
|
|
601
585
|
|
|
602
|
-
export type { ActivationFn, Config, DefaultDependencies, DefaultParamsCallback, DefaultRouteCallback, ErrorCodeKeys, ErrorCodeToValueMap, ErrorCodeValues, EventName, EventToNameMap, EventToPluginMap, EventsKeys, ForwardToCallback, LimitsConfig, Listener,
|
|
586
|
+
export type { ActivationFn, Config, DefaultDependencies, DefaultParamsCallback, DefaultRouteCallback, ErrorCodeKeys, ErrorCodeToValueMap, ErrorCodeValues, EventName, EventToNameMap, EventToPluginMap, EventsKeys, ForwardToCallback, GuardFn, LimitsConfig, Listener, NavigationOptions, Navigator, Options, Params, Plugin, PluginMethod, QueryParamsMode, QueryParamsOptions, RouteParams, RouteTreeState, Router, RouterError, SimpleState, State, StateMeta, StateMetaInput, SubscribeFn, SubscribeState, Subscription, TransitionMeta, TransitionPhase, TransitionReason, Unsubscribe };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/index.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/index.ts":{"bytes":1276,"imports":[],"format":"esm"}},"outputs":{"dist/esm/index.mjs":{"imports":[],"exports":[],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":0}},"bytes":0}}}
|
package/package.json
CHANGED
package/src/base.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface SimpleState<P extends Params = Params> {
|
|
|
11
11
|
params: P;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export type TransitionPhase = "deactivating" | "activating"
|
|
14
|
+
export type TransitionPhase = "deactivating" | "activating";
|
|
15
15
|
|
|
16
16
|
export type TransitionReason = "success" | "blocked" | "cancelled" | "error";
|
|
17
17
|
|
|
@@ -80,7 +80,7 @@ export interface RouterError extends Error {
|
|
|
80
80
|
*
|
|
81
81
|
* All options are optional and have sensible defaults. Options can be combined to achieve
|
|
82
82
|
* complex navigation behaviors. The options object is stored in state.meta.options and is
|
|
83
|
-
* available to
|
|
83
|
+
* available to guards and event listeners.
|
|
84
84
|
*
|
|
85
85
|
* @see {@link Router.navigate} for navigation method that accepts these options
|
|
86
86
|
* @see {@link State.meta} for where options are stored after navigation
|
|
@@ -121,11 +121,11 @@ export interface NavigationOptions {
|
|
|
121
121
|
*
|
|
122
122
|
* Without `reload`:
|
|
123
123
|
* - Navigation to current route throws SAME_STATES error
|
|
124
|
-
* - No lifecycle hooks
|
|
124
|
+
* - No lifecycle hooks execute
|
|
125
125
|
* - No events are fired
|
|
126
126
|
*
|
|
127
127
|
* With `reload`:
|
|
128
|
-
* - Full transition executes (deactivate → activate
|
|
128
|
+
* - Full transition executes (deactivate → activate)
|
|
129
129
|
* - All lifecycle hooks run again
|
|
130
130
|
* - TRANSITION_SUCCESS event fires with same state
|
|
131
131
|
* - State object is recreated (new reference)
|
|
@@ -178,16 +178,16 @@ export interface NavigationOptions {
|
|
|
178
178
|
*
|
|
179
179
|
* @description
|
|
180
180
|
* When `true`, bypasses only the canDeactivate lifecycle hooks for segments being
|
|
181
|
-
* deactivated. canActivate guards
|
|
181
|
+
* deactivated. canActivate guards still execute normally. This allows
|
|
182
182
|
* forcing navigation away from routes with confirmation dialogs or unsaved changes.
|
|
183
183
|
*
|
|
184
184
|
* Skipped vs executed:
|
|
185
185
|
* ```
|
|
186
186
|
* // Normal transition
|
|
187
|
-
* deactivate(fromSegments) → activate(toSegments) →
|
|
187
|
+
* deactivate(fromSegments) → activate(toSegments) → success
|
|
188
188
|
*
|
|
189
189
|
* // With forceDeactivate: true
|
|
190
|
-
* [skip deactivate] → activate(toSegments) →
|
|
190
|
+
* [skip deactivate] → activate(toSegments) → success
|
|
191
191
|
* ```
|
|
192
192
|
*
|
|
193
193
|
* ⚠️ Data loss risk: Bypassing canDeactivate means unsaved changes will be lost
|
|
@@ -214,21 +214,12 @@ export interface NavigationOptions {
|
|
|
214
214
|
*
|
|
215
215
|
* @description
|
|
216
216
|
* Automatically set by the router when a navigation is triggered by a redirect from
|
|
217
|
-
*
|
|
217
|
+
* guards or lifecycle hooks. This flag is used internally to track redirect chains
|
|
218
218
|
* and is stored in state.meta.options.redirected.
|
|
219
219
|
*
|
|
220
220
|
* @default false (auto-set by router during redirects)
|
|
221
221
|
*
|
|
222
222
|
* @example
|
|
223
|
-
* // Middleware triggers automatic redirect
|
|
224
|
-
* router.useMiddleware((toState, fromState, opts) => {
|
|
225
|
-
* if (!isAuthenticated && toState.name !== 'login') {
|
|
226
|
-
* // Router will automatically set redirected: true
|
|
227
|
-
* return { name: 'login', params: { next: toState.path } };
|
|
228
|
-
* }
|
|
229
|
-
* });
|
|
230
|
-
*
|
|
231
|
-
* @example
|
|
232
223
|
* // Accessing redirect flag in lifecycle
|
|
233
224
|
* router.addActivateGuard('dashboard', (toState, fromState) => {
|
|
234
225
|
* if (toState.meta?.options?.redirected) {
|
package/src/index.ts
CHANGED
|
@@ -24,7 +24,7 @@ export type {
|
|
|
24
24
|
} from "./base";
|
|
25
25
|
|
|
26
26
|
// Router types (base types without Router dependency)
|
|
27
|
-
// Note: Route, RouteConfigUpdate, ActivationFnFactory,
|
|
27
|
+
// Note: Route, RouteConfigUpdate, ActivationFnFactory,
|
|
28
28
|
// PluginFactory, BuildStateResultWithSegments are in @real-router/core
|
|
29
29
|
export type {
|
|
30
30
|
Options,
|
|
@@ -32,10 +32,10 @@ export type {
|
|
|
32
32
|
ForwardToCallback,
|
|
33
33
|
DefaultParamsCallback,
|
|
34
34
|
ActivationFn,
|
|
35
|
+
GuardFn,
|
|
35
36
|
DefaultDependencies,
|
|
36
37
|
Config,
|
|
37
38
|
Plugin,
|
|
38
|
-
Middleware,
|
|
39
39
|
SubscribeState,
|
|
40
40
|
SubscribeFn,
|
|
41
41
|
Listener,
|
package/src/limits.ts
CHANGED
|
@@ -19,14 +19,6 @@ export interface LimitsConfig {
|
|
|
19
19
|
*/
|
|
20
20
|
maxPlugins: number;
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
* Maximum number of middleware functions in the navigation pipeline.
|
|
24
|
-
* Controls middleware chain length to prevent stack overflow and performance issues.
|
|
25
|
-
*
|
|
26
|
-
* @default 50
|
|
27
|
-
*/
|
|
28
|
-
maxMiddleware: number;
|
|
29
|
-
|
|
30
22
|
/**
|
|
31
23
|
* Maximum number of event listeners per event type.
|
|
32
24
|
* Prevents memory leaks from excessive listener registration.
|
package/src/router.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Base router types without Router class dependency.
|
|
5
5
|
*
|
|
6
6
|
* Router-dependent types (Route, RouteConfigUpdate, ActivationFnFactory,
|
|
7
|
-
*
|
|
7
|
+
* PluginFactory) are defined in @real-router/core
|
|
8
8
|
* to avoid circular dependencies.
|
|
9
9
|
*/
|
|
10
10
|
|
|
@@ -161,6 +161,11 @@ export type ActivationFn = (
|
|
|
161
161
|
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
162
162
|
) => boolean | Promise<boolean | State | void> | State | void;
|
|
163
163
|
|
|
164
|
+
export type GuardFn = (
|
|
165
|
+
toState: State,
|
|
166
|
+
fromState: State | undefined,
|
|
167
|
+
) => boolean | Promise<boolean>;
|
|
168
|
+
|
|
164
169
|
export type DefaultDependencies = object;
|
|
165
170
|
|
|
166
171
|
export interface Config {
|
|
@@ -188,9 +193,6 @@ export interface Plugin {
|
|
|
188
193
|
teardown?: () => void;
|
|
189
194
|
}
|
|
190
195
|
|
|
191
|
-
// eslint-disable-next-line sonarjs/redundant-type-aliases
|
|
192
|
-
export type Middleware = ActivationFn;
|
|
193
|
-
|
|
194
196
|
export interface SubscribeState {
|
|
195
197
|
route: State;
|
|
196
198
|
previousRoute?: State | undefined;
|
|
@@ -241,9 +243,9 @@ export interface Navigator {
|
|
|
241
243
|
* Defines the contract for router implementations. The actual Router class in
|
|
242
244
|
* @real-router/core implements this interface with full functionality.
|
|
243
245
|
*
|
|
244
|
-
* This interface uses `
|
|
246
|
+
* This interface uses `GuardFn | boolean` for guard types to avoid circular
|
|
245
247
|
* dependencies. The concrete Router class in @real-router/core narrows this to
|
|
246
|
-
* `
|
|
248
|
+
* `GuardFnFactory | boolean` for more precise type checking.
|
|
247
249
|
*/
|
|
248
250
|
export interface Router {
|
|
249
251
|
/**
|
|
@@ -253,7 +255,7 @@ export interface Router {
|
|
|
253
255
|
* @param guard - Guard function or boolean
|
|
254
256
|
* @returns this for method chaining
|
|
255
257
|
*/
|
|
256
|
-
addActivateGuard: (name: string, guard:
|
|
258
|
+
addActivateGuard: (name: string, guard: GuardFn | boolean) => this;
|
|
257
259
|
|
|
258
260
|
/**
|
|
259
261
|
* Register a deactivation guard for a route.
|
|
@@ -262,7 +264,7 @@ export interface Router {
|
|
|
262
264
|
* @param guard - Guard function or boolean
|
|
263
265
|
* @returns this for method chaining
|
|
264
266
|
*/
|
|
265
|
-
addDeactivateGuard: (name: string, guard:
|
|
267
|
+
addDeactivateGuard: (name: string, guard: GuardFn | boolean) => this;
|
|
266
268
|
|
|
267
269
|
/**
|
|
268
270
|
* Remove an activation guard from a route.
|
|
@@ -294,7 +296,7 @@ export interface Router {
|
|
|
294
296
|
* Dispose the router and release all resources.
|
|
295
297
|
*
|
|
296
298
|
* Stops the router if active, calls plugin teardown, clears all event
|
|
297
|
-
* listeners,
|
|
299
|
+
* listeners, routes, and dependencies. After disposal, all
|
|
298
300
|
* mutating methods throw a ROUTER_DISPOSED error. Idempotent — safe to
|
|
299
301
|
* call multiple times.
|
|
300
302
|
*/
|