/** * @deijose/nix-ionic / IonRouterOutlet.ts — v2.5 * * Architecture: "core API + ion-router-outlet motor" (with auto-bootstrap) * * Changes vs v2.4: * * (E) Manual lifecycle dispatch on duration-0 transitions. * EMPIRICAL FINDING: .commit() with `duration: 0` * (used for direction: "none" and "root") does NOT fire the lifecycle * events. We confirmed this with `replace("/login")` after a logout — * the leaving page's `ionViewWillLeave` never ran. * * The fix: when `direction` is "none" or "root", we synthesize the * events ourselves around the commit() call, in the order Ionic * documents: * 1. WillLeave on the leaving page (BEFORE commit starts) * 2. WillEnter on the entering page (BEFORE commit starts) * 3. await commit() (instantaneous when duration=0) * 4. DidEnter on the entering page (AFTER commit resolves) * 5. DidLeave on the leaving page (AFTER DidEnter — Ionic docs) * * For animated transitions ("forward"/"back") we still rely on Ionic * to fire the events, since those go through the full animation path * where the events ARE wired correctly. * * Kept from earlier versions: * (A) Anti-flash on first mount. * (B) StackManager `back` recognition. * (C) _hideInactivePages defensive sweep after every transition. * (D) Manual lifecycle dispatch on first mount (no leaving page). * * Subclass note for IonPage users: if you override `onInit()` in a * subclass, you MUST call `super.onInit()` first. The base IonPage uses * onInit to wire `watch()` calls onto the lifecycle signals — without the * super call, your `ionViewWillEnter`/etc. methods never fire. */ import { NixComponent } from "@deijose/nix-js"; import type { NixTemplate } from "@deijose/nix-js"; import { type PageLifecycle } from "./lifecycle"; import { NavigationManager } from "./navigation"; export type GuardResult = boolean | string | { redirect: string; } | void | undefined; export interface PageContext { lc: PageLifecycle; params: Record; query: Record; } export interface RouteDefinition { path: string; component: (ctx: PageContext) => NixComponent | NixTemplate; beforeEnter?: (ctx: PageContext) => GuardResult | Promise; /** * Per-route cache policy override. When set, takes precedence over the * outlet-level policy for this route. * * - `true` — use the outlet's default cache policy * - `false` — never cache this route (cleanup on leave) * - `{ max: N }` — cache at most N instances of this route * - `{ ttl: N }` — cache entries expire after N milliseconds * - `{ max: N, ttl: N }` — both bounds */ cache?: boolean | CachePolicy; } /** * Bounded cache policy for cached pages. * * - `max`: maximum number of cached entries per tab. When exceeded, the * least-recently-used entry is evicted. Default: unlimited. * - `ttl`: time-to-live in milliseconds. Entries older than this are * evicted on next access or by a background timer. Default: unlimited. * - `strategy`: "lru" (default) evicts the least-recently-used entry when * `max` is reached. "fifo" evicts the oldest entry. */ export interface CachePolicy { max?: number; ttl?: number; strategy?: "lru" | "fifo"; } export interface IonRouterOutletOptions { /** Enable/disable caching globally. Set to false to disable all caching. */ cache?: boolean; /** * Bounded cache policy applied to all cached routes (unless overridden * per-route via `RouteDefinition.cache`). */ cachePolicy?: CachePolicy; defaultAnimation?: unknown; tabs?: string[]; skipAutoBootstrap?: boolean; /** * Optional NavigationManager for centralized navigation state, hooks, * and programmatic tab switching. When provided, the outlet delegates * stack management and transition state to the manager. */ navigation?: NavigationManager; } export declare function IonBackButton(defaultHref?: string): NixTemplate; export declare class IonRouterOutlet extends NixComponent { private _routesByPath; private _wildcardRoute; private _enableCache; private _cachePolicy; private _routeCachePolicies; private _defaultAnimation; private _stacks; private _cache; private _nav; private _activePageEl; private _activeCacheKey; private _activeTabKey; private _outletEl; private _routeEffectDisposer; private _isTransitioning; private _pendingNav; private _guardsInCoreRouter; constructor(routes: RouteDefinition[], opts?: IonRouterOutletOptions); private _resolveRouteDefinition; private _createPageEl; private _mountComponent; private _hideInactivePages; private _transitionTo; render(): NixTemplate; invalidateCache(routePath: string, params?: Record, tabKey?: string, query?: Record): void; clearCache(): void; /** * Clear all cached pages for a specific tab. Useful when leaving a tab * permanently or for memory management. */ clearTabCache(tabKey: string): void; /** The NavigationManager used by this outlet (if any). */ get navigation(): NavigationManager | null; }