UNPKG

@riogz/router

Version:

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

41 lines (40 loc) 1.28 kB
import { Router } from '../types/router'; /** * Enhances a router with navigation capabilities. * * This module provides the core navigation functionality including: * - Programmatic navigation to routes * - Navigation to default routes * - Transition cancellation * - State transition management * - Error handling for navigation failures * * Navigation supports various options like: * - Replace vs push navigation * - Force reload of same routes * - Skip transition process * - Custom navigation options * * @template Dependencies - Type of dependencies available during navigation * @param router - Router instance to enhance with navigation capabilities * @returns Enhanced router with navigation functionality * * @example * ```typescript * // Basic navigation * router.navigate('user', { id: '123' }) * * // Navigation with options * router.navigate('user', { id: '123' }, { replace: true }) * * // Navigation with callback * router.navigate('user', { id: '123' }, (err, state) => { * if (err) { * console.error('Navigation failed:', err) * } else { * console.log('Navigation successful:', state) * } * }) * ``` */ export default function withNavigation<Dependencies>(router: Router<Dependencies>): Router<Dependencies>;