UNPKG

@riogz/router

Version:

A simple, lightweight, powerful, view-agnostic, modular and extensible router

39 lines (38 loc) 1.31 kB
import { Router } from '../types/router'; /** * Enhances a router with state management capabilities. * * This module provides functionality for: * - Creating and managing router state objects * - State comparison and equality checking * - State forwarding and redirection * - Not found state handling * - State serialization and deserialization * - Parameter forwarding between states * * Router state represents the current navigation state including: * - Route name and parameters * - Current path and meta information * - Query parameters and hash * - Navigation source and options * * @template Dependencies - Type of dependencies available in the router * @param router - Router instance to enhance with state management * @returns Enhanced router with state management functionality * * @example * ```typescript * // Create a state * const state = router.makeState('users.detail', { id: '123' }) * * // Check state equality * const isEqual = router.areStatesEqual(state1, state2) * * // Check if state is descendant * const isDescendant = router.areStatesDescendants(parentState, childState) * * // Get current state * const currentState = router.getState() * ``` */ export default function withState<Dependencies>(router: Router<Dependencies>): Router<Dependencies>;